0% found this document useful (0 votes)
16 views

3 - Remove all vowels from a given string using pointers

The document provides a C program to remove all vowels from a given string using both switch-case and pointer techniques. It includes code snippets for each method, detailing the logic for checking vowels and manipulating strings. The program reads input, processes it to exclude vowels, and outputs the modified string.

Uploaded by

ankurmourya99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

3 - Remove all vowels from a given string using pointers

The document provides a C program to remove all vowels from a given string using both switch-case and pointer techniques. It includes code snippets for each method, detailing the logic for checking vowels and manipulating strings. The program reads input, processes it to exclude vowels, and outputs the modified string.

Uploaded by

ankurmourya99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Code for Interview

Code for Interview (Youtube)

Problem Statement

Program to remove all vowels from a given string using pointers

Input:

CodeforInteview
Code for Interview

In C Using Switch Case

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

int check_vowel(char);

int main()
{
char s[100], t[100];

int i, j = 0;

scanf("%[^\n]s",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);
Code for Interview

printf("%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;
Code for Interview

default:

return 0;

In C using pointers
Code for Interview

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#define TRUE 1

#define FALSE 0

int check_vowel(char);

int main()

char string[100], *temp, *pointer, ch, *start;

gets(string);

temp = string;

pointer = (char*)malloc(100);

if( pointer == NULL )

exit(EXIT_FAILURE);

start = pointer;
Code for Interview

while(*temp)

ch = *temp;

if ( !check_vowel(ch) )

*pointer = ch;

pointer++;

temp++;

*pointer = '\0';

pointer = start;

strcpy(string, pointer);

free(pointer);

printf("%s\n", string);

return 0;
Code for Interview

int check_vowel(char a)

if ( a >= 'A' && a <= 'Z' )

a = a + 'a' - 'A';

if ( a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')

return TRUE;

return FALSE;

------------------------------------- END -----------------------------------------------

You might also like