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
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 |
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 |
what is difference between #include<stdio.h> and #include"stdio.h"
Find MAXIMUM of three distinct integers using a single C statement
Why do some versions of toupper act strangely if given an upper-case letter?
What is the Difference between Macro and ordinary definition?
3 Answers Bosch, Cognizant, College School Exams Tests, Motorola,
How can I change their mode to binary?
What is anagram in c?
Explain how do you determine the length of a string value that was stored in a variable?
What is multidimensional arrays
What is scope and lifetime of a variable in c?
What is calloc in c?
Do you know the use of 'auto' keyword?
Explain the Difference between the New and Malloc keyword.