Code:
#include <stdio.h>
#include <stdlib.h>
FILE *in;
char **readFile();
void main()
{
in = fopen("sentences.in", "rt");
char **words;
words = readFile(in);
printf("%s\n", words[0]);
}
char **readFile(FILE *in)
{
char *word, **warr;
word = (char*)malloc(25 * sizeof(char));
for(int i = 0; i < 28; ++i)
{
fscanf(in, "%s", word);
if(i >= 28)
{
printf("Only %d words can be used in your input file.", 20);
}
warr[i] = calloc(strlen(word) + 1, sizeof(char));
strcpy(warr[i], word);
}
printf("%s\n", words[0]);
return warr;
}
Prints word from input file in readFile but doesn't do it in main after the return. It's not being pass correctly and I'm not sure how to do it :/