通信滤除$字符分段保留重要信息代码
我的学记|刘航宇的博客

通信滤除$字符分段保留重要信息代码

刘航宇
4年前发布 /正在检测是否收录...
温馨提示:
本文最后更新于2021年03月23日,已超过1467天没有更新,若内容或图片失效,请留言反馈。

通信中滤除$字符分段保留重要信息代码
实现效果
图片[1] - 通信滤除$字符分段保留重要信息代码 - 我的学记|刘航宇的博客
初级代码main实现

#include "stdio.h"
int main() {
int i, j;
char temp[16][32] = { 0 };
char str[128] = { 0 };
printf("please input a string\n");
scanf("%s", str);
printf("%s\n", str);
char* p = &str[0];
i = 0; j = 0;
while (1)
{
if (*p == 0)
{
break;
}
if (*p != '$')
{
temp[i][j] = *p;
j++;
}
else
{
i++;
j = 0;
}
p++;
}
for (j = 0; j <= i; j++)
{
printf("%s\t", temp[j]);
}
return 0;
}
 

进阶调用函数

#include "stdio.h"
void fun(char *p){
int i,j;
char temp[16][32]={0};
i=0;
j=0;
while(1)
{
    if(*p==0)
    {break;}
    if(*p!='$')
    {
    temp[i][j]=*p;
    j++;
    }
    else
    {i++;
    j=0;
    }
    p++;

}
for(j=0;j<=i;j++)
{
printf("%s\t",temp[j]);
}
return;
}
int main(){
char str[128]={0};
printf("please input string\n");
scanf("%s",str);
fun(str);
printf("\n");
return 0;
}

再次进阶

#include "stdio.h"
int len;
char **fun(char *p){
int i,j;
static char *m[16];
static char temp[16][32]={0};
i=0;
j=0;
while(1)
{
    if(*p==0)
    {break;}
    if(*p!='$')
    {
    temp[i][j]=*p;
    j++;
    }
    else
    {i++;
    j=0;
    }
    p++;

}
for(j=0;j<=i;j++)
{
printf("%s\t",temp[j]);
}
len=i+1;
for(i=0;i<16;i++)
{
m[i]=&temp[i][0];
}
return m; //&m[0]
}
int main(){
char **k;
int i;
char str[128]={0};
printf("please input string\n");
scanf("%s",str);
k=fun(str);
for(i=0;i<len;i++){
    printf("%s\t",*k);
    }
return 0;
}
© 版权声明
THE END
喜欢就支持一下吧
点赞 3 分享 赞赏
评论 共1条
取消
  1. 头像
    默默
     · 
    回复

    nb