Answer to Question #200315 in C for Pragadeesh

Question #200315

Design a C program to remove characters from the first string which are present in the second string.


1
Expert's answer
2021-05-29T01:34:19-0400
#include <stdio.h>
#include <string.h>


//This function checks if string contains letter
int stringContainsLetter(char intputString[],char letter){
	int j=0;
	while(intputString[j] != '\0'){
		if(intputString[j]==letter){
			return 1;
		}
		j++;
	}
	return 0;
}


//The start point of the program
int main()
{
	char firstString[100];//the first string
	char secondString[100];//the second string
	char tempFirstString[100];
	int i=0;
	int counter=0;
	int length;


	//get the first string from the keyboard
	printf("Enter the first string: ");
	gets(firstString);
	//get the second string from the keyboard
	printf("Enter the second string: ");
	gets(secondString);
	//remove characters from the first string which are present in the second string.
	while(firstString[i] != '\0'){
		if(stringContainsLetter(secondString,firstString[i])==0){
			tempFirstString[counter]=firstString[i];
			counter++;
		}
		i++; 
	}
	tempFirstString[counter]='\0';
	strcpy(firstString,tempFirstString);
	//display the first string after removing characters
	printf("The first string after removing characters: %s\n", firstString);


	//delay
	getchar();
	getchar();
	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