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

SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve
FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran
TaigaTaiga
Every great hero faces trials, and you—yes, YOU—are no exception!
Chat with Taiga

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