GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Tech FAQs  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 24 of 99    Print  
write a program to count the occurrence of following C keywords in a file and calculate the sum?

1.int
2.char
3.static
4.struct
5.union
6.return

  
Total Answers and Comments: 1 Last Update: July 24, 2007     Asked by: rafiuddin 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
July 24, 2007 11:41:26   #1  
baseersd Member Since: June 2007   Contribution: 34    

RE: write a program to count the occurrence of followi...

#include<stdio.h>

int main()
{
char keywords[6][10]={"int","char","static","struct","union","return"};
int count[7]={0};
FILE *fp;
char str[100];
fp=fopen("test1.c","r");
if(fp==NULL)
{
 printf("nCannot open the file");
 return 0;           
}
while(!feof(fp))
{
       fgets(str,sizeof(str),fp);
       puts(str);
   if(strstr(str,keywords[0]))
   {
    count[0]++;
    count[6]++;                         
   }
   if(strstr(str,keywords[1]))
   {
    count[1]++;
    count[6]++;                         
   }
   if(strstr(str,keywords[2]))
   {
    count[2]++;
    count[6]++;
   }
   if(strstr(str,keywords[3]))
   {
    count[3]++;
    count[6]++;
   }
   if(strstr(str,keywords[4]))
   {
    count[4]++;
    count[6]++;
   }
   if(strstr(str,keywords[5]))
   {
    count[5]++;
    count[6]++;
   }                 
}
printf("nNO of int s  = %d",count[0]);
printf("nNo of char s = %d",count[1]);
printf("nNo of static s = %d",count[2]);
printf("nNo of struct s = %d",count[3]);
printf("nNo of union s= %d",count[4]);
printf("nNo of return s= %d",count[5]);
printf("nTotal Keywords = %d",count[6]);
getch();
return 0;
}



 


 
Is this answer useful? Yes | No

 Related Questions

Latest Answer : NitinMishra is absoulutely right that number generated by rand() is not random. I think this code will serve the purpose.....#include #include int main(){    // Just for example, i have taken the list    ...
Read Answers (5) | Asked by : Ankesh Tiwari

Latest Answer :     #includeint main(){char ch;int i,count=0;FILE *fp=fopen("check.txt(txt file)","r");while(!feof(fp)) {        for(i=1;i
Read Answers (2) | Asked by : simran

I want to convert a string (ex: 567.2.2.2) into integer or array of integer and i have to check 567 is greater then or less than 256 or not and i have to dispaly. this string is in a file

Write a program that would input integer from 40-127 and output the equivalent octal hexadecimal value.
Read Answers (2) | Asked by : save_you

Q1. write a program to find a given number is armstrong number or not ?Q2write a program which accepts a filename as a command line argument and reverse the contents of the file(i.e first character becomes the last character of the file and so on ?Q3 how can i call a function given its name as a string ?Q4 How to swap low-order byte and high order byte in an integer without using temporary variable?Q5 If we develop a project in C, then how can we create an .exe file of it?Q6 how to print 1 to 100
please let me know the answers to my email address as i having the interview in TCS so please please please please let me know  
Read Answers (16) | Asked by : M.srilatha

Q1 How to swap Low-order byte and high order byte in an integer without using temporary variable ?Q2 write a program to print numbers from 1 to 100 without using any condition checking ?Q3 If we develop a project in C,then how can we create an .exe file of it?Q4 Write a program which accepts a filename as a command like argument and reverse the contents of the file (i.e firs character becomesthe last character of the file and so on)input: the program takes the file name whose content should be
Read Answers (7) | Asked by : M.srilatha

Char str[]="DOLLAR";Here , you have the base address of array i.e. str.By using only one pointer variable, you have to replace the occurrence of 'L' with '$$'. (after replacement, it should be DO$$$$AR)can any body suggest efficient method?
Read Answers (2) | Asked by : pavan kumar reddy
Tags : Pointer

Latest Answer : In c every function by default returns an integer value. By using void we mean a value zero is return to the environment i.e., operating system. ...
Read Answers (3) | Asked by : mohammed arif

View Question | Asked by : umesh

I have a class defined belowclass A{ int *m_ptr; A(){}};main(){ int *loc_ptr; A a1,a2;}I have to write a copy constructor for this classPlease help in this problemThanks in Advance.
View Question | Asked by : Ravikannan


 Sponsored Links

 
Related Articles

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

C++ Static Functions

C Static Functions Static member functions have a class scope and they do not have access to the this pointer of the class When a member is declared as static a static member of class it has only one data for the entire class even though there are many objects created for the class The main usage of
 

What is Data File

In a logical data model, the conceptual data model which is based on the business semantic is being defined. Thus, entities and relationships and corresponding table and column design, object oriented classes, and XML tags, among other things are being laid regardless of the database will be physica
 

What is the use of COUNT with DISTINCT option

COUNT is a group function returns&nbsp;result by summarizing multiple rows. All group by value function will have the usage of DISTINCT or ALL option and so is the COUNT which uses the DISTINCT option. DISTINCT option is used to enforce uniqueness and&nbsp; if combined with COUNT is used to
 

printf() Function Return Value

What is the return value from printf() function? printf function always returns the number of characters printed. Let us understand this with an example: main() { int a=10; printf(&quot;%d&quot;,printf(&quot;%d %d %d&quot;, a,a,a)); } In this above program the inner printf i
 

What is the default return value of a function?

The default return value from a function is int. In other words, unless explicitly specified the default return value by compiler would be integer value from function.&nbsp;&nbsp; When a programmer wants other than integer values to be returned from function then it is essential that the pro
 

How to develop compile and run a C program

The steps involved in building a C program are: 1. First program is created by using any text editor and the file is stored with extension as .c 2. Next the program is compiled. There are many compilers available&nbsp;like GNU C compiler called as gcc, Sun compiler, Borland compiler which is pop
 

exit and return statements

&nbsp; How does the exit () and return () differ exit () is used to exit the program as a whole. In other words it returns control to the operating system. After exit () all memory and temporary storage areas are all flushed out and control goes out of program. In contrast, the return () stateme
 

SQL Programming

SQL Programming Overview Anybody who has done something for a long time has probably wanted to change how things work at some point or another. A worker at a mill might have found a more efficient way of cutting logs, or a mathematics teacher might have had a hand in changing a school&rsquo;s al
 

WinRunner Programming Concepts

If you want to create WinRunner scripts that are highly efficient, there are important programming concepts that you will want to become familiar with. Understanding these concepts will provide you with a large number of key benefits. In addition to understanding these concepts, you must also learn
 





About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape