First, the fopen
function does not return the file size, see fopen . In your case, you may even notice that you are pointing to a variable of type FILE*
.
To do this, you should read the entire file in some way. In this case, there is a function that you can go through the file.
This example is very simple but I believe it will work for you.
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 does not make much sense to allocate memory for the TODO file when you use only each line of it. In your case, you read a line, associating string
with the file pointer. You read another, and associate a new string, and do not concatenate it.