Im remaking a quiz-app i made a long time ago...
heres a piece of the code
As you can see it takes input from a file called question.txt.Code:int read_quiz_questions() { int error; char question[BUFSIZ]; char question_header[]="/*question*/\n"; FILE *quiz_question; quiz_question=fopen("question.txt","r"); if(quiz_question==0){ perror("\n"); printf("Cant read questions from file.\n"); printf("Press a key to exit.\n"); error=0; getch(); exit(1); } else{ fgets(question,BUFSIZ,quiz_question); if(strcmp(question,question_header)==0){ do{ if(fgets(question,BUFSIZ,quiz_question)==0){ printf("All questions are solved.\n"); } printf("%s\n",question); } while(fgets(question,BUFSIZ,quiz_question)!=NULL); } error=1; } return error; }
The file question.txt looks like this.
Normally my code would give as output this.Code:/*question*/ Who am i? where do i live? Where did the previous question went???
But its giving this as output.Code:Who am i? where do i live? Where did the previous question went???
So somehow the second question dropped out... (wich is on the 3d line of the file).Code:Who am i? Where did the previous question went???
I alrdy tried to clear the buffer after fgets took the /*question*/
as input.
But that didnt worked.
So i dont really know what i should try/do next.
Suggestions are welcome
::edit::
sry bout the stupid indentation... its always the same in my compiler it looks fine. But if i paste it in here it get messed up. Somehow the code, /code thing throws in spaces at certain places.



LinkBack URL
About LinkBacks



