Ok, fine - you reply while I think about it
So now I can fix yours instead
> First of all, main always returns an int
So do it - don't just say it.
Your example shuffles uneasly off the end of the function.
> fgets(sentence, 80,stdin);
Why the size difference?
fgets ( sentence, sizeof(sentence), stdin );
works just as well, and you don't have to think "now does this allow for \0 or not".
> char temp[newlen];
This isn't even valid 'C' - you can't declare arrays with variable length. To do this, you would need to call malloc.
The important thing to realise about this problem is that the new string can never be longer that the old string, so I would think it would be ok to re-use it in place.
Code:
#include <stdio.h>
void noblank(char *string) {
int i, j;
for ( i = 0, j = 0 ; string[i] != '\0' ; i++ ) {
if ( string[i] != ' ' ) string[j++] = string[i];
}
string[j] = '\0';
}
int main ( ) {
char test[] = "hello world";
noblank( test );
printf( "%s\n", test );
return 0;
}