/* takes spaces out of a string in-place * 2007-06-30 */ #include void pack(char *str) { int i,j; for(i=0;str[i] && str[i]!=' ';i++) ; /* optimization */ for(j=i;str[i];i++) { if(str[i]!=' ') str[j++]=str[i]; } str[j]=0; } int main() { char test[] = "I have defined the hundred per cent American as ninety-nine per cent an idiot. -- George Bernard Shaw"; printf("%s\n", test); pack(test); printf("%s\n", test); return 0; }