2
C code to remove strings spaces is not working. It stops at execution.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void removerSpacos(char str[]) {
int i, j;
int tam = strlen(str);
for(i=0; i<tam; i++) {
if(str[i] != ' ') {
str[j] = str[i];
j++;
}
}
str[j] = '\0';
}
int main()
{
char frase[] = "Ola Mundo!";
removerSpacos(frase);
printf("%s", frase);
return 0;
}
How to leave the string with 1 space? Between the words, there in the phrase "Hello World" has 2, and in the code it removes all spaces.
@Jjoao do not know what happened, I could swear I was right. I tidy up. I wanted to follow his algorithm, but it really doesn’t work if the intention is to leave some.
– Maniero