im not exaclty sure what you mean by buffer, I was planning to read the whole text file into an array. Then when inserting it into the linked list I will split it into seperate words, this is because I need to be able to search the list to check how many times a word appears in the text.
I also need to be able to dynamically allocate the memory for the array, as my program has to be able to cope with the user inputting the name of the file.
I have written the code below to do this, but I am sure this is incorrect as the first piece seg faults at the while statement and the second piece doesn't compile as the putc 2nd statement makes a pointer from an integer without a cast.
Code:
char readdata(char *name){
char *x;
x = calloc(1, sizeof(FILE));
FILE *ifp;
int i = 0;
ifp = fopen(name, "r");
while ((x[i] = getc(ifp)) != EOF){
i++;
}
return *x;
}
Code:
char readdata(char *name){
char *x;
x = calloc(1, sizeof(FILE));
FILE *ifp;
int i = 0;
char c;
ifp = fopen(name, "r");
while ((c = getc(ifp)) != EOF){
putc(c, x[i]);
i++;
}
return *x;
}