answersLogoWhite

0

#include <stdio.h>

#include <string.h>

main()

{

char str[124],str_cpy[124];

char wrd[24];

void *ret;

int i,j,cnt_str,cnt_wrd,cnt_cpy,res = 0;

printf("Enter the string: ");

ret = gets(str);

printf("Enter word to remove: ");

ret = gets(wrd);

top:

cnt_str = strlen(str);

cnt_wrd = strlen(wrd);

ret = strstr(str,wrd);

if(ret != NULL)

{

cnt_cpy = (unsigned int)ret -(unsigned int)str;

strncpy(str_cpy,str,cnt_cpy);

str_cpy[cnt_cpy - 1] = '\0';

strncat(str_cpy, (ret + cnt_wrd),(cnt_str - cnt_wrd));

strcpy(str, str_cpy);

res++;

}

else if(res == 0) printf("Word not found\n");

else goto last;

goto top;

last:

printf("New string: %s\n",str);

}

that the answer

User Avatar

Wiki User

12y ago

Still curious? Ask our experts.

Chat with our AI personalities

BlakeBlake
As your older brother, I've been where you are—maybe not exactly, but close enough.
Chat with Blake
DevinDevin
I've poured enough drinks to know that people don't always want advice—they just want to talk.
Chat with Devin
ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi

Add your answer:

Earn +20 pts
Q: C program to delete a word from a sentence?
Write your answer...
Submit
Still have questions?
magnify glass
imp