Last active
January 3, 2016 13:09
Revisions
-
mygnu revised this gist
Jan 17, 2014 . 1 changed file with 1 addition and 18 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -34,21 +34,4 @@ void removeXtraSpaces(char str[], char nstr[]) } }
-
mygnu revised this gist
Jan 17, 2014 . 1 changed file with 24 additions and 20 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,9 @@ int main(int argc, char *argv[]) { char mystr[50] = {"The brown fox."}; //gets(mystr); char result[50];// = "______________"; printf("%s \n", mystr); removeXtraSpaces(mystr, result); @@ -20,16 +12,28 @@ main(int argc, char *argv[]) } 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++; } } { flag = SPACE; } -
mygnu created this gist
Jan 17, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ #define SPACE 1 #define NONSPACE 0 #include "header.h" // all required header files void removeXtraSpaces(char str[],char nstr[]); int main(int argc, char *argv[]) { char mystr[20] = "The brown fox"; //gets(mystr); char result[20]; 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 != ' ') { *nstr = *str; } else if (*str == ' ') { flag = SPACE; } else if (flag == SPACE) { flag = NONSPACE; *nstr = ' '; } str++; nstr++; } *str = '\0'; }