青浦区网站建设费用,襄阳购物网站开发设计,仿36氪wordpress,常州市金坛建设局网站实例要求#xff1a;给定任意的字符串#xff0c;清除字符串中的空格#xff0c;并将其输出#xff1b;实例分析#xff1a;1、指针函数实现#xff0c;需要注意指针函数的返回值是一个指针类型#xff1b;2、字符类型的数组实现#xff0c;循环遍历并赋给新的数组给定任意的字符串清除字符串中的空格并将其输出实例分析1、指针函数实现需要注意指针函数的返回值是一个指针类型2、字符类型的数组实现循环遍历并赋给新的数组输出清除字符串中的空格后新的字符串即可示例代码一、指针函数 #include stdio.hchar *p NULL;char *clear_space(char *s){p s;while(*s ! \0){if(*s ! ){*p *s;}s;}*p \0;return p;}int main(int argc, char const *argv[]){char a[] hh j jn lll ;clear_space(a);printf(%s\n,a);return 0;}运行结果 linuxubuntu:~/work/test1$ gcc t6.c linuxubuntu:~/work/test1$ ./a.out hhjjnlll二、数组实现 #include stdio.h#include stdlib.h#include string.hvoid clear_space(char s[]){int len strlen(s);char new_s[len];int i 0;for (int j 0; j len; j){if (s[j] ! ){new_s[i] s[j];}}new_s[i] \0;printf(%s\n, new_s); }int main(int argc, char const *argv[]){char s[] abc de fg kk ;clear_space(s);return 0;}
运行结果 linuxubuntu:~/work/test1$ gcc t6.c linuxubuntu:~/work/test1$ ./a.out abcdefgkk