Write a C program to delete all vowels from a string.
#include <stdio.h>
#include <string.h>
int main() {
int i = 0, j = 0, k, flag;
char sentence[256], output[256];
/* vowels in lowercase and uppercase */
char vowel[10] = {'a', 'e', 'i', 'o', 'u',
'A', 'E', 'I', 'O', 'U'};
/* get the input sentence from the user */
printf("Enter your input sentence:");
fgets(sentence, 256, stdin);
sentence[strlen(sentence) - 1] = '\0';
/* copy characters other than vowels to output array */
while (sentence[i] != '\0') {
flag = 0;
for (k = 0; k < 10; k++) {
if (vowel[k] == sentence[i]) {
flag = 1;
break;
}
}
if (!flag) {
output[j++] = sentence[i];
}
i++;
}
output[j] = '\0';
#include <string.h>
int main() {
int i = 0, j = 0, k, flag;
char sentence[256], output[256];
/* vowels in lowercase and uppercase */
char vowel[10] = {'a', 'e', 'i', 'o', 'u',
'A', 'E', 'I', 'O', 'U'};
/* get the input sentence from the user */
printf("Enter your input sentence:");
fgets(sentence, 256, stdin);
sentence[strlen(sentence) - 1] = '\0';
/* copy characters other than vowels to output array */
while (sentence[i] != '\0') {
flag = 0;
for (k = 0; k < 10; k++) {
if (vowel[k] == sentence[i]) {
flag = 1;
break;
}
}
if (!flag) {
output[j++] = sentence[i];
}
i++;
}
output[j] = '\0';
/* copy the contents of output to sentence */
strcpy(sentence, output);
/* print the result */
printf("After deleting all vowels: %s\n", sentence);
return 0;
}
Output:
jp@jp-VirtualBox:~/$ ./a.out
Enter your input sentence:Expenditures Allowances
After deleting all vowels: xpndtrs llwncs
Enter your input sentence:Expenditures Allowances
After deleting all vowels: xpndtrs llwncs
No comments:
Post a Comment