I have a simple problem to solve:
Read a string, print the string without space and the number of spaces.
I could do this using 2 strings, one that will store the user string and other that will store the same string without spaces. But I would like to do this using only one string.
What I have so far:
while(str[i] != '\0'){
if(str[i] == ' '){
contEsp += 1;
}else{
strcpy(&str[i - contEsp], &str[i]);
}
i++;
}
The problem:
It's not counting number of spaces.
If the user types double space or more, the program doesn't count and doesn't remove spaces.
Questions:
Whats the problem with my code?
Is it possible to do this using just one string?