pgm to find number of words starting with capital letters
in a file(additional memory usage not allowed)(if a word
starting with capital also next letter in word is capital
cann't be counted twice)

Answers were Sorted based on User's Feedback



pgm to find number of words starting with capital letters in a file(additional memory usage not al..

Answer / shiva

int flag=0,count=0;
FILE *in=fopen("in.txt","r");
while(!feof(in))
{
if( isupper( fgetc(in) ) && flag==0)
{
flag=1;
count++;
}
else if( fgetc(in) ==' ')
flag=0;
}
printf("Count=%d",count);

// PROGRAM VERIFIED WITH SAMPLE INPUT

Is This Answer Correct ?    28 Yes 8 No

pgm to find number of words starting with capital letters in a file(additional memory usage not al..

Answer / vadivelt

I havent write the code to read the no of words starts with
capital letter for a file. But for normal sentence given as
input.


#include<stdio.h>
#include<conio.h>

int main()
{
char *ptr;
int count = 0;
ptr = (char *)malloc(200);
printf("ENTER THE SENTENCE\n");
ptr = gets(ptr);
while(*ptr != '\0')
{
/*This condition is used for the first word
in the sentence*/
if(count == 0 && (*ptr >=65 && *ptr <= 90))
{
count++;
}
else if(*(ptr-1) == ' ' && (*ptr >=65 &&
*ptr <= 90))
{
count++;
}
ptr++;
}
printf("\nNO OF WORDS STARTS WITH CAPITAL LETTER
IS: %d\n", count);
getch();
}

Is This Answer Correct ?    7 Yes 1 No

Post New Answer

More C Interview Questions

What will be the output of following program #include main() { int x,y = 10; x = y * NULL; printf("%d",x); }

1 Answers  


Why structure is used in c?

0 Answers  


What are pointers? What are stacks and queues?

0 Answers   Hexaware,


how do you redirect stdout value from a program to a file?

1 Answers  


Which command is more efficient? *(ptr+1) or ptr[1]

3 Answers  






How we add our function in liabrary as liabrary function. Exp. we want use our int factorical(int); function as int pow(int,int); function working in math header file.

1 Answers  


Create a structure to specify data on students given below: Roll number, Name, Department, Course, Year of joining Assume that there are not more than 450 students in the college. 1.write a function to print names of all students who joined in a particular year 2.write a function to print the data of a student whose roll number is given

0 Answers   XYZ,


Give the output for the following program. #define STYLE1 char main() { typedef char STYLE2; STYLE1 x; STYLE2 y; clrscr(); x=255; y=255; printf("%d %d\n",x,y); }

2 Answers   ADITI,


4) Write a program that takes a 5 digit number and calculates 2 power that number and prints it.

5 Answers  


What does s c mean in text?

0 Answers  


What is the use of keyword VOLATILE in C?

1 Answers  


Is swift based on c?

0 Answers  


Categories