Remove vowels from a string in C

  • برمجة سي c

Remove vowels from a string in C

 

C program to remove or delete vowels from a string. If the input is "C programming," then the output is "C prgrmmng."

In the program, we create a new string and process input string character by character. If a vowel is present, we exclude it otherwise we copy it. After the input ends, we copy the new string into it. Finally, we obtain a sequence of characters without vowels.

الأجوبة

#include <stdio.h>
#include <string.h>
int check_vowel(char);

int main()
{
  char s[100], t[100];
  int c, d = 0;

  printf("Enter a string to delete vowels\n");
  gets(s);

  for (c = 0; s[c] != '\0'; c++) {
    if (check_vowel(s[c]) == 0) {     // If not a vowel
      t[d] = s[c];
      d++;
   }
  }

  t[d] = '\0';

  strcpy(s, t);  // We are changing initial string. This is optional.

  printf("String after deleting vowels: %s\n", s);

  return 0;
}

int check_vowel(char t)
{
  if (t == 'a' || t == 'A' || t == 'e' || t == 'E' || t == 'i' || t == 'I' || t =='o' || t=='O' || t == 'u' || t == 'U')
    return 1;

  return 0;
}

هل كان المحتوى مفيد؟

القوائم الدراسية التي ينتمي لها السؤال

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...