5
I want to remove the spaces of a string, example:
Pedro Henrique Ribeiro
Would be:
Pedrohenriqueribeiro
The code I made, it takes away the space, but it duplicates a letter:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char**argv){
char string[101];
int x, i, a;
printf("Foneca uma string com espacos em branco: ");
gets(string);
printf("%s\n",string);
for(i=0; i<strlen(string); i++){
if(string[i]==' '){
string[i]=string[i+1];
}
}
printf("String sem espaços em branco: %s\n", string);
return 0;
}
Instead of changing the string you already have, generate a new one by adding a character to the character. When it’s space you skip the insertion ;)
– Oralista de Sistemas
Did any of the answers solve your problem? Do you think you can accept one of them? If you haven’t already, see [tour] how to do this. You would help the community by identifying the best solution for you. You can only accept one of them, but you can vote for any question or answer you find useful on the entire site (if you have enough score).
– Maniero