Vote count:
0
I want a code to read a text file that is include some question and then select one of the questions in random and show for user till all of the question shows;
For example question:
How old are you?
Where are you from?
Now, this is my code but i don't Know to continue.
int main()
{
int i = 0, line = 5;
char ch[1000];
char *str;
time_t t;
srand((unsigned) time(&t));
FILE *myfile;
myfile = fopen("question.txt","r");
if (myfile== NULL)
{
printf("can not open file \n");
return 1;
}
while (fgets(ch,1000, myfile)!=NULL)
printf("%s",ch);
fclose(myfile);
line = 5;
int counter;
for( i = 0 ; i < line ; i++ ) {
counter = rand() % 6;
printf("first question: %s\n", ch[counter]);
}
return 0;
}
How can i to continue?
asked 1 min ago
read text file and show text line in random
Aucun commentaire:
Enregistrer un commentaire