I am trying to rebuild a string that has already had its initial spaces removed. The problem is I'm not sure the end of the last word gets a '\0' stapled to it or not....ahh The string is user defined and I'm now trying to eliminate internal spaces..and especially any after the last character in the string..here's the function;
too much time has been spent....please throw me a line!!!!
im tryin'
Code:void leading_spaces(char string[]) { int i=0,c=0; while(string[i]==' ') /*gets rid of leading zeros*/ { i++; } while(string[i]!='\0') /*rebuilds string w/o leading spaces*/ { string[c]=string[i]; c++; i++; } string[c]='\0'; /*places terminator after last character*/ } void all_spaces(char string[]) { int i=0,c=0; while(string[i]!='\0'&&string[i]!=' ') { string[c]=string[i]; i++; c++; while(string[i]==' '&&string[i]!='\0') { i++; } while(string[i]!='\0') { i--; string[c]=string[i]; c++; i++; puts(string); } } string[c]='\0'; } void display_line(char string[]) { int i=0; while(string[i]!='\0') { while(string[i]!=' '&&string[i]!='\0') { printf("%c",string[i]); i++; } if(string[i]!='\0') { printf("\n"); i++; if(string[i]==' '||string[i]=='\0') string[i]='\0'; } } }
[code][/code]tagged by Salem