First, the function of fopen
does not return the file size, see in fopen. In your case, you might even notice that you arrow to a variable of type FILE*
.
To do this, you must read the whole file somehow. In case, there is a function that you can scroll through the file.
This example below is very simple but I believe it will work for your case.
int GetFileSize(FILE *f)
{
fseek(f, 0, SEEK_END); // move para o fim do arquivo
size = ftell(f); // pega o ponto em que está
fseek(f, 0, SEEK_SET); // volta para o início do arquivo
}
Just call GetFileSize(p)
to receive the file size.
while (fgets(arquivo,sizeof(arquivo),p)) {
printf(" %s",arquivo );
It doesn’t make much sense for you to allocate memory to the TODO file when you just use every line of it. In your case, you read a line, associate to string
with the file pointer. You read another, and associate a new string, and do not concatenate with it.