I'm not so talented with pointers. My function returns only the address and not the word itself.
char* randstring(){
char words[20];
FILE *fp;
int i = 0, j =0, ran = 0;
srand(time(NULL));
fp = fopen("text.txt", "r");
//get size of the file
for(; fgets(words , sizeof(words), fp); j++);
ran = rand() % 10;
rewind(fp);
for( i = ran; i < j ; i++){
fgets(words, sizeof(words), fp);
}
return words;
}
The goal of this function is to return a list of words from a text file, after that, I write in a File. Where exactly is the error with my pointer?