Created
June 6, 2014 12:52
-
-
Save kkd927/80c09f5669ac69679131 to your computer and use it in GitHub Desktop.
Code to erase blank before and after string in C/C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char * space_remove(char *str) | |
{ | |
// change BUF_SIZE depending on the length of your string | |
char buf[BUF_SIZE]={0,}; | |
char *p; | |
p = strtok(str, "\r\n\t "); | |
strcat(buf, p); | |
while(p!=NULL){ | |
p = strtok(NULL, "\r\n\t "); | |
if(p!=NULL) { | |
strcat(buf, " "); | |
strcat(buf, p); | |
} | |
} | |
memset(str, '\0', BUF_SIZE); | |
strcpy(str, buf); | |
return str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment