Answer to Question #204944 in C for Ali khan

Question #204944

Write a program to delete all vowels from a sentence. Assume that the sentence is not 

more than 80 characters long.


1
Expert's answer
2021-06-11T17:49:53-0400
#include <stdio.h>


char* del_vowels(char* s) {
    char* vowels = "aeiouyAEIOUY";
    int n = 12;
    int is_vowel;
    int i;
    char* p = s;
    char* q = p;

    while (*p != '\0') {
        is_vowel = 0;
        for (i=0; i<n; i++) {
            if (*p == vowels[i]) {
                is_vowel = 1;
                break;
            }
        }
        if (!is_vowel) {
            *q = *p;
            q++;
        }
        p++;
    }
    *q = *p;
    return s;
}

int main()
{
    char buf[80];
    printf("Entera a sentence:\n");
    gets(buf);
    del_vowels(buf);
    printf("The sentece withowt vowels is:\n%s\n", buf);

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS