1. Write a C program to count the number of occurrence
of
a specific word in the given strings.
(for e.g. Find how many times the word “live” comes in the
sentence “Dream as if you’ll live forever, live as if
you’ll die today ”)

Answers were Sorted based on User's Feedback



1. Write a C program to count the number of occurrence of a specific word in the given strings. ..

Answer / ankur

#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char str[40],ch;
int num;
cout<<"Entre a string :";
cin.getline(str,40);
cout<<"Entre a character :";
cin>>ch;
for(int i=0;i!='\0';++i)
{
if(str[i]==ch)
num=num+1;
}
cout<<num;
getch();
}

Is This Answer Correct ?    20 Yes 74 No

1. Write a C program to count the number of occurrence of a specific word in the given strings. ..

Answer / jyoti

#include<stdio.h>
#include<conio.h
#include<string.h>
void main()
{
char st[200],nw[20];
int i,j=0;
clrscr();
printf("enter string");
gets(st);
printf("enter new string");
gets(nw);
for(i=0;st[i]!='\0';i++)
{if (strcmp(nw,st)==0)
j=j++;
}}
getch();
}

Is This Answer Correct ?    68 Yes 183 No

Post New Answer

More C Interview Questions

What is const volatile variable in c?

0 Answers  


Can true be a variable name in c?

0 Answers  


What is c language and why we use it?

0 Answers  


what do the 'c' and 'v' in argc and argv stand for?

0 Answers   TISL,


1.)how to find d most repeated word in a string? string ="how do you do"?? output should be do

1 Answers   AAS, Nagarro, Vuram,






can we initialize all the members of union?

2 Answers  


Which weighs more, a gram of feathers or a gram of gold?

2 Answers  


what is foreign key in c language?

1 Answers   ADP,


how can i make a program with this kind of output.. Enter a number: 5 0 01 012 0123 01234 012345 01234 0123 012 01 0

4 Answers   Wipro,


What is extern c used for?

0 Answers  


Explain why can’t constant values be used to define an array’s initial size?

0 Answers  


1. main() { printf("%d",printf("HelloSoft")); } Output?

3 Answers   HCL,


Categories