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

what is the use of using linked list and array?

10 Answers   Infosys, TCS,


Why is sizeof () an operator and not a function?

0 Answers  


Can i use Two or More Main Funtion in any C program.?

4 Answers  


How can I find out the size of a file, prior to reading it in?

0 Answers  


How to run c Program without using IDE of c. means if program made in notepad.then how to compile by command prompt.

1 Answers   HP, TCS,






If one always ought to act so as to produce the best possible circumstances, then morality is extremely demanding. No one could plausibly claim to have met the requirements of this "simple principle." . . . It would seem strange to punish those intending to do good by sentencing them to an impossible task. Also, if the standards of right conduct are as extreme as they seem, then they will preclude the personal projects that humans find most fulfilling. From an analytic perspective, the potential extreme demands of morality are not a "problem." A theory of morality is no less valid simply because it asks great sacrifices. In fact, it is difficult to imagine what kind of constraints could be put on our ethical projects. Shouldn't we reflect on our base prejudices, and not allow them to provide boundaries for our moral reasoning? Thus, it is tempting to simply dismiss the objections to the simple principle. However, in Demands of Morality, Liam Murphy takes these objections seriously for at least two distinct reasons. First, discussion of the simple principle provides an excellent vehicle for a discussion of morality in general. Perhaps, in a way, this is Murphy's attempt at doing philosophy "from the inside out.". . . Second, Murphy's starting point tells us about the nature of his project. Murphy must take seriously the collisions between moral philosophy and our intuitive sense of right and wrong. He [must do so] because his work is best interpreted as intended to forge moral principles from our firm beliefs, and not to proscribe beliefs given a set of moral principles. [Murphy] argues from our considered judgments rather than to them. . . For example, Murphy cites our "simple but firmly held" beliefs as supporting the potency of the over-demandingness objection, and nowhere in the work can one find a source of moral values divorced from human preferences. Murphy does not tell us what set of "firm beliefs" we ought to have. Rather, he speaks to an audience of well-intentioned but unorganized moral realists, and tries to give them principles that represent their considered moral judgments. Murphy starts with this base sense of right and wrong, but recognizes that it needs to be supplemented by reason where our intuitions are confused or conflicting. Perhaps Murphy is looking for the best interpretation of our convictions, the same way certain legal scholars try to find the best interpretation of our Constitution. This approach has disadvantages. Primarily, Murphy's arguments, even if successful, do not provide the kind of motivating force for which moral philosophy has traditionally searched. His work assumes and argues in terms of an inner sense of morality, and his project seeks to deepen that sense. Of course, it is quite possible that the moral viewpoints of humans will not converge, and some humans have no moral sense at all. Thus, it is very easy for the moral skeptic to point out a lack of justification and ignore the entire work. On the other hand, Murphy's choice of a starting point avoids many of the problems of moral philosophy. Justifying the content of moral principles and granting a motivating force to those principles is an extraordinary task. It would be unrealistic to expect all discussions of moral philosophy to derive such justifications. Projects that attempt such a derivation have value, but they are hard pressed to produce logical consequences for everyday life. In the end, Murphy's strategy may have more practical effect than its first-principle counterparts, which do not seem any more likely to convince those that would reject Murphy's premises. 1) The author suggests that the application of Murphy's philosophy to the situations of two different groups: a) would help to solve the problems of one group but not of the other. b) could result in the derivation of two radically different moral principles. c) would be contingent on the two groups sharing the same fundamental beliefs. d) could reconcile any differences between the two groups. 2) Suppose an individual who firmly believes in keeping promises has promised to return a weapon to a person she knows to be extremely dangerous. According to Murphy, which of the following, if true, would WEAKEN the notion that she should return the weapon? a) She also firmly believes that it is morally wrong to assist in any way in a potentially violent act. b) She believes herself to be well-intentioned in matters of right and wrong. c) The belief that one should keep promises is shared by most members of her community. d) She derived her moral beliefs from first-principle ethical philosophy. 3) The passage implies that a moral principle derived from applying Murphy's philosophy to a particular group would be applicable to another group if: a) the first group recommended the principle to the second group. b) the moral viewpoints of the two groups do not converge. c) the members of the second group have no firmly held beliefs. d) the second group shares the same fundamental beliefs as the first group. 4) According to the passage, the existence of individuals who entirely lack a moral sense: a) confirms the notion that moral principles should be derived from the considered judgments of individuals. b) suggests a potential disadvantage of Murphy's philosophical approach. c) supports Murphy's belief that reason is necessary in cases in which intuitions are conflicting or confused. d) proves that first-principle strategies of ethical theorizing will have no more influence over the behavior of individuals than will Murphy's philosophical approach. 5) Which of the following can be inferred about "doing philosophy from the inside out?" a) Murphy was the first philosopher to employ such an approach. b) It allows no place for rational argument in the formation of ethical principles. c) It is fundamentally different from the practice of first-principle philosophy. d) It is designed to dismiss objections to the "simple principle." 6) A school board is debating whether or not to institute a dress code for the school's students. According to Murphy, the best way to come to an ethical decision would be to: a) consult the fundamental beliefs of the board members. b) analyze the results of dress codes instituted at other schools. c) survey the students as to whether or not they would prefer a dress code. d) determine whether or note a dress code has ever been instituted in the school's history

0 Answers   Accenture,


implement general tree using link list

1 Answers   Wipro,


34.what are bitwise shift operators? 35.what are bit fields? What is the use of bit fields in a structure declaration? 36.what is the size of an integer variable? 37.what are the files which are automatically opened when a c file is executed? 38.what is the little endian and big endian? 39.what is the use of fflush() function? 40.what is the difference between exit() and _exit() functions? 41.where does malloc() function get the memory? 42.what is the difference between malloc() and calloc() function? 43.what is the difference between postfix and prefix unary increment operators?

0 Answers  


any function have arguments one or more OR not . it is compulsary a) any function compulsary have one or more arguments b) any function did not have arguments. It is not compulsary c) it is optional it is not compulsary d) none of the above

0 Answers  


What is c method?

0 Answers  


What is the maximum length of an identifier?

0 Answers  


#include<stdio.h> int main(){ int a[]={1,2,3,5,1}; int *ptr=a+4; int y=ptr-a; printf("%d",y); }

3 Answers   Zoho,


Categories