//字符串操作两头堵模型练习 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include<string.h> //去除字符串中的空格 //const char *pin的解释:const char *pin是用来限制指针pin指向的数据是个常量,不允许修改, //但是并不限制实参指针指向的数据也必须是一个常量 //这是为了防止传过来的参数pin所指向的数据不可以修改,但是却在函数里做了修改,导致程序报错,这是一种标准的写法 int removespace(const char *pin,char *pout){ int ERRO_MSG = 0; //验证传入参数是否为空 if (pin == NULL || pout==NULL) { ERRO_MSG = 1; printf("pin == NULL || pout==NULL erro msg key:%d ", ERRO_MSG); return ERRO_MSG; } //两头堵模型就是要准备两个辅助指针,一个在头部,一个在尾部 int i = 0, j = 0; //定义不是空格的字符的个数 int index = 0; //不清楚具体循环次数,一般使用while或者do...while... //i从头开始 //注意:pin[i]==" "这么些是错误的," "是字符串(2个字符,' '也算一个),pin[1]是一个char类型 while (pin[i] != '