im trying out using malloc in array of characters by reading each word from that text file and putting it in a array so the array size is exact my problem is when i run the program it makes segmentation fault im not sure where the problem is and if i used the malloc right
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char *buf;
FILE *inputFile;
inputFile = fopen("aa1.txt","r");
int length = fread(buf, 1, sizeof(buf), inputFile);
buf = (char *)malloc(length * sizeof(char));
printf("%d",buf[1]);
fclose(inputFile);
return 0;
}