-
Notifications
You must be signed in to change notification settings - Fork 5
/
To_find_keywords.c
48 lines (48 loc) · 1.01 KB
/
To_find_keywords.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
void main()
{
int i,j,count=0;
char c='\n';
char ch;
FILE *fp;
char Keyword[32][15]={
"extern","return","union","const","float","short",
"auto","double","int","struct","break","else","long",
"goto","sizeof","voltile","do","if","static","while",
"unsigned","continue","for","signed","void","default",
"switch","case","enum","register","typedef","char"
};
fp=fopen("file.txt","w");
if(fp==NULL)
{
printf("File not exist");
exit(1);
}
for(i=0;i<32;i++)
{
for(j=0;j<strlen(Keyword[i]);j++)
{
fputc(Keyword[i][j],fp);
}
fputc(c,fp);
}
fclose(fp);
fp=fopen("file.txt","r");
if(fp==NULL)
{
printf("File not exist");
exit(1);
}
ch=fgetc(fp);
while(!feof(fp))
{
if(ch=='\n')
{ count++; }
ch=fgetc(fp);
}
fclose(fp);
printf("%d",count);
}