I am writing a program in c to identify functions' signature and copy in another file.
Idea was to determine parenthesis in any line and to copy that line to a file. Afterwards we can check for return type and parameters, so as to differentiate constructs if, while from user defined functions except main.
But my code stuck in infinite loop. Can't find the problem.
find_sig.c
#include <stdio.h>
int main()
{
int count=0;
char c;
FILE *f1,*f2;
f1=fopen("input.c","r");
f2=fopen("output.c","w");
while((c=getc(f1))!=EOF)
{
do
{
if(c=='(')
{
fseek(f1,-count,1);
do{
putc(c,f2);
}while((c=getc(f1))!=')');
count=0;
}
else
count++;
}while((c=getc(f1))!=10);
count=0;
}
fclose(f1);
fclose(f2);
return 0;
}
input.c
#include<stdio.h>
void fun();
int main()
{
fun();
return 0;
}
void fun()
{
printf("hello");
}
Any other idea for determining functions' signature will be very helpful.