2
I need to make a code that takes a string typed by the user, count how many vowels there are in that string and swap all vowels from that string to a letter that the user defines, I did almost everything, I just can’t replace all the vowels of the word by the letter the user type, which error?
#include <stdio.h>
#include <string.h>
int main()
{
char string[100];
char ch1,ch2,texto[100];
int x, tam,i,j,contador=0;
char vogais[] = "aeiouAEIOU";
printf ("Digite uma palavra: ");
gets(texto);
for (i=0;i<strlen(texto);i++){
for (j=0;j<strlen(vogais);j++){
if (texto[i] == vogais[j]){
contador++;
}
}
}
if (contador == 1){
printf ("\n\nA palavra informada possui 1 vogal\n\n");
}else{
printf ("\n\nA palavra informada possui %d vogais\n\n", contador);
}
printf("Digite a palavra novamente :");
gets(string);
printf ("Qual letra voce vai substituir? :\n");
scanf ("%c", &ch1);
printf ("Letra que vai substituir :\n");
scanf (" %c", &ch2);
tam=strlen(string);
for (x=0;x<tam;x++){
if (string[x]==ch1){
string[x]=ch2;
}
}
printf ("%s", string);
return 0;
}