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 / balaji ganesh

#include<stdio.h>
#include<string.h>
void main()
{
char s[200],c[20],v=' ';
int i=0,j,f,n=0;
printf("enter string: ");
gets(s);
printf("enter new string: ");
gets(c);
while(i<strlen(s))
{
j=f=0;
while(j<strlen(c))
{
if(s[i++]!=c[j++])
{
f=1;i--;break;
}
}
if((f==0)&&(i==strlen(s)||s[i]==' ')&&(v==' '))
n++;
v=s[i++];
}
printf("the word %d times occured",n);
}

Is This Answer Correct ?    91 Yes 41 No

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

Answer / taruna.kashyap

plz give me answer of this question.

Is This Answer Correct ?    59 Yes 45 No

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

Answer / anil

only balaji's ws de ri8 answer... thanx 2 him...

Is This Answer Correct ?    23 Yes 15 No

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

Answer / taruna chaudhary

thanx ram u r exelent.

Is This Answer Correct ?    17 Yes 15 No

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

Answer / abhishek

#include<stdio.h>
#include<string.h>
main()
{
int i,occ=0;
char str[100],ch;
printf("enter string");
scanf("%s",str);
printf("enter character");
scanf("%s",ch);
for(i=0;str[i]!='\0';i++)
{
if(str[i]==ch)
{
occ+=1;
}
else
{
occ+=0;
}
}
printf("occurance of %s in %s is %d",ch str occ);
getch();
}

Is This Answer Correct ?    14 Yes 12 No

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

Answer / ranjith kumar

#include<stdio.h>
//#include<conio.h>
void main()
{
int i=0,chr=0,sp=0,words=1,ss=0,digits=0;
char line[100],temp='a';
//clrscr();
printf("\nEnter the line:\n");
gets(line);

while(line[i]!='\0') //to check for string termination
{
if((line[i]>64&&line[i]<91)||(line[i]>96&&line[i]<123)) // ascii range of characters
chr++;
else
{
if(line[i]==32) //ascii value of space is 32
{
sp++;
if(temp!=32)
words++;
}
else
{
if(line[i]>47&&line[i]<58) //ascii range of digits
digits++;
else
ss++;
}
}
temp=line[i];
i++;
}
printf("\nNumber of characters = %d words = %d spaces %d special symbols = %d digits = %d",chr,words,sp,ss,digits);
}

Is This Answer Correct ?    7 Yes 8 No

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

Answer / aashik shrestha

#include<stdio.h>
#include<string.h>
int main()
{
char s[100];
char *p;
char s1[10];
char *q;
int i,m,j = 1,l,count = 0;

printf("Enter the text:");
gets(s);

printf("Enter the word you wanna count:");
gets(s1);

p = s;
q = s1;

l = strlen(s);
m = strlen(s1);
i = 0;

while(*(p+i)!='\0')
{
j = 0;m = 1;
while(*(p+i) != ' ' && *(q+j)!= '\0' && *(p+i)!= '\0')
{
if(*(p+i) != *(q+j)){
m= 0;
break;
}
i++;
j++;
}
if(*(p+i) == '\0')
{
break;
}

if(*(p+i) == ' '&& *(q+j) == '\0')
count++;
if(*(p+i)!= ' ')
{
i++;
}
i++;
}
if(m == 1)
count++;
printf("Total occurence of %d\n",count);
return 0;
}

Is This Answer Correct ?    4 Yes 6 No

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

Answer / ram

#include <string.h>

void main()
{
char name[] ="Dream as if you will live forever, live as if
you will die today";
char r[] ="live";
int iLen = strlen(r);

int iCount = 0;



while(1)
{
if( strstr(name,r) == NULL)
break;
strcpy(name, strstr(name,r));

strcpy(name,name+iLen);
iCount++;
}

printf("%d",iCount);



}

Is This Answer Correct ?    23 Yes 28 No

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

Answer / vikas kumar from agra

i've try my level best ..plz run this program...but u don't
mistake in typing..100% output right...just try..


#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,s,oc=0;
char str[100],substr[30];
clrscr();
printf("\n enter string");
gets(str);
printf("\n enter substr");
gets(substr);
for(s=0;substr[s];s++)
for(i=0;str[i];i++)
{
if(str[i]==substr[0])
{
j=i;
k=0;
while(str[j]==substr[k] && srt[j]!='\0' && substr[k]!='\0')
{
j++;
k++;
}
if(k==s)
{
oc++;
}
printf("\n\t\t occurrence is %d",oc);
getch();
}

Is This Answer Correct ?    18 Yes 43 No

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

Answer / vikas kumar

#include<stdio.h>
#include<conio.h>
void main()
{
int i,occ=0;
char str[100],ch;
printf("\n enter string");
scanf("%s",str);
printf("\n enter character");
scanf("%s",ch);
for(i=0;i[str]!='\0';i++)
{
if(str[i]==ch)
{
occ++;
}
}
printf("\n occurance of %c in %s is %d",ch str occ);
getch();
}

Is This Answer Correct ?    25 Yes 66 No

Post New Answer

More C Interview Questions

write a program to fined second smallest and largest element in a given series of elements (without sorting)

9 Answers   Yahoo,


How was c created?

0 Answers  


Can we replace the struct function in tree syntax with a union?

0 Answers   Huawei,


How can I convert integers to binary or hexadecimal?

2 Answers  


Write a C program that will accept a hexadecimal number as input and then display a menu that will permit any of the following operations to be carried out: Display the hexadecimal equivalent of the one's complement. (b) Carry out a masking operation and then display the hexadecimal equivalent of the result. (c) Carry out a bit shifting operation and then display the hexadecimal equivalent of the result. (d) Exit. If the masking operation is selected, prompt the user lor the type of operation (bitwise and, bitwise exclusive or, or bitwise or) and then a (hexadecimal) value for the mask. If the bit shifting operation is selected. prompt the user for the type of shift (left or right), and then the number of bits. Test the program with several different (hexadecimal) input values of your own choice.

0 Answers  






What does char * * argv mean in c?

0 Answers  


Why do we use int main?

0 Answers  


What is the purpose of main( ) in c language?

0 Answers  


Find the O/p of the following struct node { char *name; int num; }; int main() { struct node s1={"Harry",1331}; struct node s2=s1; if(s1==s2) printf("Same"); else printf("Diff"); }

1 Answers  


What does do in c?

0 Answers  


How can I do peek and poke in c?

0 Answers  


What are formal parameters?

0 Answers  


Categories