Here I have a code that is to output the vowels used in a string and ignore the consonants. However it repeats the output of the vowel if that vowel is used more than once in the input string. Is there some way that I can prevent repetition of characters outputted or some function that can achieve this same task?
#include <stdio.h>
#include <string.h>
int main()
{
int i = 0, j = 0, k;
char string[256], result[256];
char vowel[10] = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'};
printf("Enter string:");
fgets(string, 256, stdin);
string[strlen(string) - 1] = '\0';
while (string[i] != '\0')
{
for (k = 0; k < 10; k++)
{
if (vowel[k] == string[i])
{
result[j++] = string[i];
break;
}
}
i++;
}
result[j] = '\0';
strcpy(string, result);
printf ("\n");
printf("Vowel used are: %s\n\n", string);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire