1 #define _CRT_SECURE_NO_WARNINGS 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 6 7 int trimSpace(char *inbuf, char *outbuf) 8 { 9 char *tmpBuf = inbuf; 10 11 while(*tmpBuf!=‘\0‘) 12 { 13 if ((*tmpBuf) != ‘ ‘) 14 15 *outbuf++ = *tmpBuf; 16 } 17 tmpBuf++; 18 } 19 *outbuf = ‘\0‘; 20 } 21 int main() 22 { 23 char *inbuf; 24 char *outbuf = NULL; 25 outbuf =(char *)malloc(100); 26 inbuf = " abcdefg "; 27 28 trimSpace(inbuf, outbuf); 29 printf("trimSpace后outbuf:%s\n", outbuf); 30 system("pause"); 31 return 0; 32 }
原文:http://www.cnblogs.com/linst/p/4856799.html