Untitled

 avatar
user_3977588
plain_text
2 years ago
875 B
3
Indexable
 
/*
 * C Program to Remove given Word from a String
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main ()
{
	char str[100], word[100], twoD[10][30];
	int i = 0, j = 0, k = 0, len1 = 0, len2 = 0;
 
	printf ("Enter the string:\n");
	gets (str);
 
	printf ("Enter the word to be removed:\n");
	gets (word);
 
	// let us convert the string into 2D array
	for (i = 0; str[i] != '\0'; i++)
	{
		if (str[i] == ' ')
		{
			twoD[k][j] = '\0';
			k ++;
			j = 0;
		}
		else
		{
			twoD[k][j] = str[i];
			j ++;
		}
	}
 
	twoD[k][j] = '\0';
 
	j = 0;
	for (i = 0; i < k + 1; i++)
	{
		if (strcmp(twoD[i], word) == 0)
		{
			twoD[i][j] = '\0';
		}
	}
 
	j = 0;
 
	for (i = 0; i < k + 1; i++)
	{
		if (twoD[i][j] == '\0')
			continue;
		else
			printf ("%s ", twoD[i]);
	}
 
	printf ("\n");
 
	return 0;
}
Editor is loading...