C code to remove spaces in strings is not working. It stops at running.
#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] = '#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] = '%pre%';
}
int main()
{
char frase[] = "Ola Mundo!";
removerSpacos(frase);
printf("%s", frase);
return 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.