Jump to content

Help!

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
geeko

geeko

    Newbie

  • Members
  • PipPip
  • 27 posts
I have a problem printing "a question" from a text file. Can anybody tell me how to print the exact question from the text file. (the question on the txt file is ::: " 1 What is my name?" ). It only prints "1 What"

<Here's the Code>
#include <stdlib.h>
#include <stdio.h>

int main(void)
{
    
    int questionNumber;
    char question[20];
      
      FILE *cfPtr;
      
      if((cfPtr = fopen("questions.txt","r")) == NULL)
                printf("File could not be opened\n");
        
        else {
           printf("\n                          Question 1\n");
             printf("________________________________________________________________________\n\n");
                fscanf(cfPtr, "%d%s", &questionNumber,question);
           
       if(questionNumber!=0){      
           printf("%d%s\n\n",questionNumber,question);
             fscanf(cfPtr, "%d%s", &questionNumber,question);}
           
          fclose(cfPtr);
       
       }/*end else*/
       

           printf("\npress any key to continue: ");
         while(!getchar());          
           
           return 0; 
           
}

Edited by WingedPanther, 18 October 2008 - 09:46 AM.
add code tags


#2
dcs

dcs

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 775 posts
http://forum.codecal...-numbers-c.html