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 IS MAXIMUM SIZE OF AN ARRAY IN C LANGUAGE?

8 Answers   Carphone Warehouse, IBM, SAS,


How to implement call back functions ?

3 Answers   HP,


Program to find the value of e raised to power x using while loop

5 Answers   IBM, N Tech,


write a program to search for an element in a given array. If the array was found then display its position otherwise display appropriate message in c language

18 Answers   IT Park, TCS,


4)What would be the output? main() { int num=425; pf("%d",pf("%d",num)); } a)Comp error b)4425 c)4253 d)3435 e)none

10 Answers  






WHAT IS ABSTRACT DATA TYPE

4 Answers   Wipro,


What ios diff. Between %e & %f?

3 Answers   Honeywell,


what is the difference between static variable and register variable?

3 Answers  


Can a program have two main functions?

0 Answers  


Given a string write a program to print all alphabetical characters in the order of their occurance first,followed by the sum of the numeric characters then followed by the special characters in the order of their occurance.

1 Answers   College School Exams Tests, Wipro,


What is external and internal variables What is dynamic memory allocation what is storage classes in C

3 Answers  


How to implement variable argument functions ?

1 Answers   HP,


Categories