Home > Blockchain >  How can I read with fread the content of file?
How can I read with fread the content of file?

Time:12-14

given the following text-file ("file_text);

example text

I'm trying to read the content of this file in this way:

#include <stdio.h>
#include <stdlib.h>

int main(){
  char* arr = malloc(64);
  FILE* f_fd = fopen("file_txt", "r");
  fread(arr, 1, 64, f_fd);
  printf("|%s|\n", arr);
  return 0;
}

but it doesn't print the really content of the file. I see for example: |P?p| or |P^2| ..
And I don't understand why I get it.

NOTES: 64 is the max size of this file.

CodePudding user response:

The name of your file is "file_text", but you trying to open this file with:

fopen("file_txt", "r");

try to open it with "file_text" file name.

  • Related