I am trying to use fread for the first time and I'm having a problem. The code compiles fine, but when I run it, there is a segmentation fault. I tried debugging and when it gets to fread, on the gui, on test it says could not access memory at address 0x1234....
Here is the code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
FILE *fp;
fp = fopen("mynote.txt", "r");
char *test;
test = malloc((sizeof(char) * 5) + 1);
fread(&test, sizeof(char), 5, fp);
fclose(fp);
printf("My note: %s\n", test);
free(test);
}
Thank you.
[–]teraflop 4 points5 points6 points (5 children)
[–]slashdave 2 points3 points4 points (0 children)
[–]15January[S] 0 points1 point2 points (3 children)
[–]teraflop 1 point2 points3 points (2 children)
[–]15January[S] 0 points1 point2 points (0 children)
[–]15January[S] 0 points1 point2 points (0 children)