Saketh Gangam Saketh Gangam - 1 year ago 54
C Question

How to read and extract specific text from a .txt file in c

I have been given an assignment to write a program in c that reads a c program and extract functions from it.Can anyone help?

> #include<stdio.h>
> #include<conio.h>
> int c;
> FILE *file;
> file = fopen("c.c", "r");
> if (file) {
> while ((c = getc(file)) != EOF)
> putchar(c);
> fclose(file);
>
> }

Answer Source

You will fine enough help here and here.

First of all if you want to read the c file, find your answer in the first link. Second of all after opening it from the first step, you should look for types (helping yourself with the second link): bool, int, void, ..., then you will save the line with a getline().

your getline should include the following if your c file is well indent :

  • the type (including pointers if any),
  • the name of the function,
  • the parameters

Then from the first '{' you will find your function implementation. If there is any more loop inside your fonction, you have to count all the '{' in order to know where your function finishes by putting them in a LIFO.

You will have to do this until the end of the doc to know all the functions.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download