answersLogoWhite

0


Best Answer

#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);

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a c program to delete word of string?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you write a c program to find the smallest word in a string?

what is if(!(str[i]==32))


Write a C program to extract a given word from a file?

program to extract a given word from a file


How to write Java program for find longest word in a string?

class LongestWord{String str = "Ram is intelligent boy";String stringArray[] = str.split("\\s");public String compare(String st1, String st2){if(st1.length()>st2.length()){return st1;}else{return st2;}}LongestWord(){String word = "";for(int i=0;i


Bluej program-read a string and check if the given string is a palindrome?

import java.util.Scanner; public class Palindrome{ public static void main(String[] args){ String front; String back =""; char[] failure; String backwards; Scanner input=new Scanner(System.in); System.out.print("Enter a word: "); front=input.next(); front=front.replaceAll(" ", ""); failure=front.toCharArray(); for (int i=0; i&lt;failure.length; i++){ back=failure[i] + back; } if (front.equals(back)){ System.out.print("That word is a palindrome"); }else System.out.print("That word is not a palindrome"); }}


Write a program to copy the value of one string variable to another variable?

You can have two String variables (note that String variables are object references) refer to the same String object like so: String str1 = "Hello"; String str2 = str1; Now the str1 and str2 are references for the same String object containing the word "Hello". If you actually want a new String object with a copy of the contents of the original String, you use the String constructor that takes a String argument, like so: String str3 = new String(str1); Now str1 and str3 refer to SEPARATE String objects that happen to contain the same sequence of characters (the word "Hello"). Since Strings objects in Java are immutable, they can be shared without worrying about the contents used by one variable being upset by the use through another variable as might happen with char[] arrays in C or C++ so the first method is probably sufficient for most cases.

Related questions

How do you write a c program to find a word in a string?

what is if(!(str[i]==32))


How do you write a c program to find the smallest word in a string?

what is if(!(str[i]==32))


Write a PHP program to check whether the string is palindrome or not?

You can do this: &lt;?php if ( $word === strrev( $word ) ) { echo "The word is a palindrome"; } else { echo "The word is not a palindrome"; }


Write a Java Program to find occurences of given word in a text?

Check the documentation of the String class, for a method that searches for a substring.


Write a c program to count the number of word in a string?

#include&lt;stdio.h&gt; void main() { int cnt=0,i; char str[100]; printf("Enter the string "); scanf("%s",str); for(i=0;i&lt;strlen(str)-1;i++) { if(str[i]==' ') cnt++; } printf("\nTotal no. of word in string = %d",cnt); }


Write a C program to convert an upper case word to lower case and vice-versa.?

You would use the ToUpper and ToLower functions. string name = "XVengeance"; string upperName = name.ToUpper(); string lowerName = name.ToLower(); Console.WriteLine(upperName); Console.WriteLine(lowerName); Console.ReadLine(); I don't think I'm supposed to do your homework for you, but this code should get you started on making a more dynamic program.


use the word program as a direct object?

Write a program for this process.


Write a C program to extract a given word from a file?

program to extract a given word from a file


How do you write a program in C to check whether a word is a palindrome or not?

It is a simple program. i think u may understand it :#include#include#includevoid main(){char s[10]=answers.com;char x[10];int a;clrscr();strcpy(x,s);strrev(s);a=strcmp(s,x);if(a==0){printf("the entered string is palindrome");}else{printf("the entered string is not palindrome");}output:given string is not palindrome


How to write Java program for find longest word in a string?

class LongestWord{String str = "Ram is intelligent boy";String stringArray[] = str.split("\\s");public String compare(String st1, String st2){if(st1.length()>st2.length()){return st1;}else{return st2;}}LongestWord(){String word = "";for(int i=0;i


What phrase begins with the word string?

String him along is a saying. It begins with the word string.


What type of program do you use to write a letter?

The most common is Microsoft Word