Hi,
I really need some help with this project. I'm currently a beginning C student working on a wheel of fortune program. For this program a random phrase must be chosen from a text file; the same phrase cannot also be used again during the game (there are three rounds). I've started to work on this, but I'm really stuck. I think I need to have a loop with fgets instead but other than that I'm clueless Please help me. Thanks. The test text file had 43 lines that why rand is with 43
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*/
size_t i=0; /*counter for loop*/
int len; /*length of line from file*/
line=rand()%43; /*randomization of line*/
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(line--){
fgets(temp, 100, 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, "%"));
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;
}