Home » C PROGRAM » C PROGRAM TO DELETE ALL VOWELS FROM STRING

C PROGRAM TO DELETE ALL VOWELS FROM STRING

// C PROGRAM TO DELETE ALL VOWELS FROM STRING

// DATE: 09-07-2015

#include<stdio.h>

#include<conio.h>

#include<string.h>

// Declaration of Maximum Length of the String

#define MAX 100

void main()

{

            int i, j, length;

            char string[MAX], *vowel[ ] = {“a”, “e”, “i”, “o”, “u”};

            clrscr();

            printf(“Enter the String.\n”);

// gets() Function is used to take Multi-word String Input

            gets(string);

            printf(“The String is %s.\n”, string);

            length = strlen(string);

            for(i=0; i<length; i++)

            {

                        for(j=0; j<5; j++)

                        {

                                    if(string[i] == *vowel[j])

                                    {

                                                while(string[i] != ‘\0’)

                                                {

                                                            string[i] = string[i+1];

                                                            i++;

                                                }

                                                i = 0;

                                    }

                        }

            }

            string[i] = ‘\0’;

            if(string[0] == ‘\0’)

                        printf(“After deleting all vowels the String is null.”);

            else

                        printf(“After deleting all vowels the String is %s.\n”, string);

            getch();

}

C PROGRAM TO DELETE ALL VOWELS FROM STRING USING FUNCTION

// C PROGRAM TO DELETE ALL VOWELS FROM STRING USING FUNCTION

// DATE: 10-07-2015

#include<stdio.h>

#include<conio.h>

#include<string.h>

// Declaration of Maximum Length of the String

#define MAX 100

// Declaration of the Function

void delete_vowels(char *str);

void main()

{

            char string[MAX];

            clrscr();

            printf(“Enter the String.\n”);

// gets() Function is used to take Multi-word String Input

            gets(string);

            printf(“The String is %s.\n”, string);

// Calling the Function

            delete_vowels(string);

            getch();

}

// Definition of the Function

void delete_vowels(char *str)

{

            int i, j, length;

            char s[MAX], *vowel[] = {“a”, “e”, “i”, “o”, “u”};

            i = 0;

            while(*str != ‘\0’)

            {

                        s[i] = *str;

                        str++;

                        i++;

            }

            s[i] = ‘\0’;

            length = strlen(s);

            for(i=0; i<length; i++)

            {

                        for(j=0; j<5; j++)

                        {

                                    if(s[i] == *vowel[j])

                                    {

                                                while(s[i] != ‘\0’)

                                                {

                                                            s[i] = s[i+1];

                                                            i++;

                                                }

                                                i = 0;

                                    }

                        }

            }

            s[i] = ‘\0’;

            if(s[0] == ‘\0’)

                        printf(“After deleting all vowels the String is null.”);

            else

                        printf(“After deleting all vowels the String is %s.\n”, s);

}

OUTPUT OF THE PROGRAM:

Enter the String.
wonder land
The String is wonder land.
After deleting all vowels the String is wndr lnd.

C PROGRAM TO DELETE A CHARACTER FROM STRING

// C PROGRAM TO DELETE A ALPHABET OR CHARACTER FROM STRING

// AS MANY TIMES IT APPEARS IN THE STRING

// DATE: 09-07-2015

#include<stdio.h>

#include<conio.h>

#include<string.h>

// Declaration of Maximum Length of the String

#define MAX 100

void main()

{

            int i, length;

            char string[MAX], character;

            clrscr();

            printf(“Enter the String.\n”);

// gets() Function is used to take Multi-word String Input

            gets(string);

            printf(“The String is %s.\n”, string);

            printf(“Enter the Character or Alphabet which is to be deleted.\n”);

            scanf(“%c”, &character);

            printf(“The Character is %c.\n”, character);

            length = strlen(string);

            for(i=0; i<length; i++)

            {

                        if(string[i] == character)

                        {

                                    while(string[i] != ‘\0’)

                                    {

                                                string[i] = string[i+1];

                                                i++;

                                    }

                                    i = 0;

                        }

            }

            string[i] = ‘\0’;

            printf(“After deleting the character the String is %s.\n”, s);

            getch();

}

C PROGRAM TO DELETE A CHARACTER FROM STRING USING FUNCTION

// C PROGRAM TO DELETE A ALPHABET OR CHARACTER FROM STRING

// USING FUNCTION AS MANY TIMES IT APPEARS IN THE STRING

// DATE: 09-07-2015

#include<stdio.h>

#include<conio.h>

#include<string.h>

// Declaration of Maximum Length of the String

#define MAX 100

// Declaration of the Function

void delete_character(char *str, char c);

void main()

{

            char string[MAX], character;

            clrscr();

            printf(“Enter the String.\n”);

// gets() Function is used to take Multi-word String Input

            gets(string);

            printf(“The String is %s.\n”, string);

            printf(“Enter the Character or Alphabet which is to be deleted.\n”);

            scanf(“%c”, &character);

            printf(“The Character is %c.\n”, character);

// Calling the Function

            delete_character(string, character);

            getch();

}

// Definition of the Function

void delete_character(char *str, char c)

{

            int i, length;

            char s[MAX];

            i = 0;

            while(*str != ‘\0’)

            {

                        s[i] = *str;

                        str++;

                        i++;

            }

            s[i] = ‘\0’;

            length = strlen(s);

            for(i=0; i<length; i++)

            {

                        if(s[i] == c)

                        {

                                    while(s[i] != ‘\0’)

                                    {

                                                s[i] = s[i+1];

                                                i++;

                                    }

                                    i = 0;

                        }

            }

            s[i] = ‘\0’;

            printf(“After deleting the character the String is %s.\n”, s);

}

OUTPUT OF THE PROGRAM:

Enter the String.
elephant
The String is elephant.
Enter the Character or Alphabet which is to be deleted.
e
The Character is e.
After deleting the character the String is lphant.

Related Posts