Make a code that reads a text and shows without vowels. The code cannot use functions

Asked

Viewed 34 times

-2

#include<stdio.h>
#include<conio.h>

main()
{
char texto[41];
int n,i;

printf("Entre com um texto\n");  gets(texto);
for(n=0;texto[n]!='\0';n++);

i=0;
while(texto[i]!='\0')
{
   if (texto[i]== 'A' || texto[i]== 'a' || texto[i]== 'E' || texto[i]=='e' || texto[i]== 'I' || texto[i]== 'i' || texto[i]== 'O' || texto[i]== 'o' || texto[i]== 'U' || texto[i]== 'u')
      texto[i]==' ';
        }
i=i+1;


puts (texto);
}

I just started seeing C and I can’t seem to figure out this exercise.

  • https://ideone.com/nJZxyD

1 answer

0

One way to solve the problem is by using a second vector to store the new text.

#include<stdio.h>
#include<conio.h>

main()
{
    char texto[41], texto2[41];
    int n,i,vogais=0,j=0;

    printf("Entre com um texto\n");  
    gets(texto);
    i=0;
    while(texto[i]!='\0')
    {
        if (!(texto[i]== 'A' || texto[i]== 'a' || texto[i]== 'E' || texto[i]=='e' || texto[i]== 'I' || texto[i]== 'i' || texto[i]== 'O' || texto[i]== 'o' || texto[i]== 'U' || texto[i]== 'u')){
            texto2[j]=texto[i];
            j++;
        }
    i++;
    }
    texto2[i]=0;

puts (texto2);

return 0;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.