Last active
January 3, 2016 13:09
-
-
Save mygnu/8467443 to your computer and use it in GitHub Desktop.
removing all spaces form a string
This file contains 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
int | |
main(int argc, char *argv[]) | |
{ | |
char mystr[50] = {"The brown fox."}; | |
//gets(mystr); | |
char result[50];// = "______________"; | |
printf("%s \n", mystr); | |
removeXtraSpaces(mystr, result); | |
printf("%s\n", result); | |
} | |
void removeXtraSpaces(char str[], char nstr[]) | |
{ | |
int flag = NONSPACE; | |
while (*str != '\0') | |
{ | |
if(*str != ' ') | |
{ | |
flag = NONSPACE; | |
*nstr = *str; | |
nstr++; | |
} | |
else if (*str == ' ' && flag == NONSPACE) | |
{ | |
flag = SPACE; | |
*nstr = ' '; | |
nstr++; | |
} | |
str++; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment