Pages

Remove Vowels From a String in C

Friday 28 June 2013
Remove vowels string  C : C program to remove vowels from a string, or to remove, if the input string is "C programming language" so the output will be "C Programming". The program will establish us a new string and processing input string character by character, and if a vowel is something new Finder Series confirms otherwise added character in the new series, ends after the string we copy new string convoys string. A string without vowels we finally.

#include <stdio.h>
#include <string.h>

int check_vowel(char);

int main()
{
  char s[100], t[100];
  int i, j = 0;

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

  for(i = 0; s[i] != '\0'; i++)
  {
    if(check_vowel(s[i]) == 0)
    {    
      t[j] = s[i];
      j++;
    }
  }

  t[j] = '\0';

  strcpy(s, t);    //We are changing initial string

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

  return 0;
}

int check_vowel(char c)
{
  switch(c)
  {
    case 'a':
    case 'A':
    case 'e':
    case 'E':
    case 'i':
    case 'I':
    case 'o':
    case 'O':
    case 'u':
    case 'U':
      return 1;
    default:
      return 0;
  }
}

No comments:

Post a Comment