I'm trying to read the contents of a file with fread, however the contents are not being written to the ptr. I've verified with the ftell() function that the position in the stream is changing, however no content is written to the ptr.
I've implemented the same functionality in another code, the only difference being that in that case it was a struct instead of char *, I can't figure out based on the documentation why this is the case.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
// ensure proper usage
if (argc != 2)
{
fprintf(stderr, "Usage: recover infile\n");
return 1;
}
char *infile = argv[1];
// open input file
FILE *inptr = fopen(infile, "r");
if (inptr == NULL)
{
fprintf(stderr, "Could not open %s.\n", infile);
return 2;
}
char *block;
block = malloc(sizeof(char)*64);
fread(block, 1, 64, inptr);
printf(" es %s \n", block);
int position = ftell(inptr);
printf("position %d \n", position);
free(block);
fclose(inptr);
}
The malloc is currently a placeholder btw.
Any explanations as to why the data on the file isn't being written to block?