0
I’m trying to get an array to store the typed letter if it’s not a vowel, however, it’s not storing anything, just a few strange symbols appear. Follows the code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
system("cls");
char letra[10], consoante[10];
int i, x = 0;
printf("Faca um Programa que leia um vetor de 10 caracteres, e diga quantas consoantes foram lidas. Imprima as consoantes\n");
for (i = 0; i < 10; i++)
{
printf("Digite a letra: ");
fflush(stdin);
scanf("%c", &letra[i]);
if ((letra[i] == 'a') || (letra[i] == 'e') || (letra[i] == 'i') || letra[i] == 'o' || letra[i] == 'u')
{
printf("Caiu aqui");
}
else
{
consoante[i] == letra[i];
}
}
for (x = 0; x < 10; x++)
{
printf("A consoante foi: %c\n", consoante[x]);
}
system("pause");
}
I already tested the if
and the else
and is falling into the right place, but does not store in the array.
You are using the same index variable and are therefore leaving positions containing vowels with memory junk in the consonant array.
– anonimo