Could someone please guide me in how to correct this? Thank you.
Code:
int initialize_array(char phrase[], char puzzle[], char clue[]){
FILE* phraseFile; /*input file*/
char temp[100]; /*temporary array*/
int line; /*line from which word and clue are chosen*/
int i=0; /*counter for loop*/
int len; /*length of line from file*/
int count=0;
phraseFile = fopen("clues.txt", "r"); /*opens file*/
if (!phraseFile) {
fprintf(stderr, "Oops - file not opened !\n"); /*if there is error in opening file program is exited*/
exit(1);
}
while(fgets(temp,100,phraseFile)!=0){
++count;
}
line= rand()%count;
while(line--){
fgets(temp, count, phraseFile); /*gets line and stores in temp*/
}
len=strlen(temp);
if(temp[len-1]=='\n')
temp[len-1]=0; /*places the null terminating character after word*/
/*separates clues from word*/
strcpy(clue,strtok(temp, "%"));
/*
strcpy(phrase,strtok(NULL,"%"));*/
char tmp[WORD_LENGTH];
strcpy(tmp,strtok(NULL,"%"));
strcpy(phrase, tmp + 1);
strcpy(puzzle,phrase);
/*strcpy(puzzle,phrase);*/
while(i<strlen(puzzle)){
if(isalpha(puzzle[i])){
puzzle[i] = '*'; /*hides word*/
}
++i;
}
fclose(phraseFile); /*closes file*/
return i;
}