Question: I have two `.c` files: one contains the main and the other contains all of my functions.

In my main I have a part where I want to read a char at a time the loop looks like this: 

```
while(ch = ReadFile(fp)) != EOF)
{
    // Code
}

```

where `ch` is an integer (`int ch;`) and `fp` is a file pointer (`FILE* fp;`).

And (different `.c` file ---):

```
int ReadFile(FILE* fp)
{
    // Some code
    return n; // The next char
}

```

Does anyone know how I can read one char at a time from the main this way, using this method?

Answer: 
Simply: 

```
while(ch != EOF)
{ 
    ch = fgetc(fp);
    //process ch
}

```

Keep in mind that `fgetc` is declared as an `int`.

Or if you wanted to build a string char by char you could read the file char by char to dynamically allocated memory like so (assuming `fp` is open for reading):

```
char *data = NULL, *tmp;
int ch, bff = 0;

while(ch != EOF)
{
    if(!(tmp = realloc(data, bff + 2)))
    {
        free(data);
        return 1;
    }
    data = tmp;
    ch = fgetc(fp);   //or your readfile function assuming it works the same as fgetc
    data[bff++] = ch;
}
data[bff] = '\0';

```

just `free(data)` when you are done with it
try this:

```
int ReadFile(FILE* fp, int *buffer)
{
    if(fp != NULL)
    {
        *buffer = fgetc(fp);
        return *buffer;
    }
    else return NULL;
}

```