#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp = fopen("lr.txt", "r");
fseek(fp, 0L, SEEK_END);
int size = ftell(fp);
fseek(fp, 0L, SEEK_SET);
char *lorem_ipsum;
int i = 0;
lorem_ipsum = (char*) malloc(sizeof(char) * size);
while(fscanf(fp, "%s\n", lorem_ipsum) != EOF)
{
printf("%s", lorem_ipsum[i]);
i++;
}
fclose(fp);
return 0;
}
This program compiled and ran, however, what happened was that I got a segfault and I don't know quite exactly what's wrong with this program. Could somebody help me with the pointer error I got?