c语言处理字符中的空格 函数

来源:互联网 发布:java识别图片文字 编辑:程序博客网 时间:2024/06/09 20:14
#include <stdio.h>
#include <ctype.h>

#include <string.h>


void del_space_string(char *string,int n);

int main(){

char string[] = "NI hao we l i k er tong";


del_space_string(string,strlen(string));


printf("%s\n",string);


return 0;
}


void del_space_string(char *string,int n){


int i = 0;
int j = 0;
int space = 0;

for(i=0;i<n;i++){

if(isspace(*(string+i+space))){
space+=1;
j = (space+i);
while(isspace(*(string+j))){
j++;
space++;
}
}
*(string+i)= *(string+i+space);
}
printf("%s\n",string);
}