-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileHandling11.c
107 lines (98 loc) · 2.54 KB
/
FileHandling11.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* C program to Display the Function Names defined in C Source File
*/
#include <stdio.h>
#include <string.h>
void check(char *c,int p1, int p2);
void display(char *c, int p1);
void main(int argc, char **argv)
{
FILE *fp;
char ch[100];
char *pos1, *pos2, *pos3;
fp=fopen(argv[1], "r");
if (fp == NULL)
{
printf("\nFile unable to open");
return;
}
else
printf("\nFile Opened to display function names :\n");
while (1)
{
if ((fgets(ch, 100, fp)) != NULL)
{
if ((strstr(ch, "/*")) == NULL)
{
pos1 = strchr(ch, '('); /* check opening brace */
if (pos1)
{
pos2 = strchr(ch,')'); /* check oclosing brace */
if (pos2)
{
pos3 = strchr(ch,';'); /* check for semicolon */
if ((pos1 < pos2) && (pos3 == NULL) || (pos3 < pos1))
{
check(ch, pos1 - ch, pos2 - ch);
}
else continue;
}
else continue;
}
else continue;
}
else continue;
}
else break;
}
fclose(fp);
}
/* To check if it is a function */
void check(char *c, int p1, int p2)
{
int i, flag = 0, temp = p1;
if ((c[p1 + 1] == ')'))
{
display(c, p1);
return;
}
for (i = p1 + 1; i < p2; i++)
{
if ((c[i] != ' ') || (c[i] == ')'))
{
flag = 1;
}
if (flag == 0)
{
display(c, p1);
return;
}
else
{
flag = 0;
while (c[--temp] != ' ');
for (i = 0; i < temp; i++)
if (c[i]==' ')
{
flag = 1;
}
if (flag == 0)
{
display(c, p1);
return;
}
else
return;
}
}
}
/* To display function name */
void display(char *c,int p1)
{
int temp = p1, i;
while (c[--temp] != ' ');
for (i = temp + 1; i < p1; i++) /* Print name of function character by character */
printf("%c", c[i]);
printf("\n");
return;
}