C- help with Clear screen

Home Forums C Programming C- help with Clear screen

Viewing 4 reply threads
  • Author
    Posts
    • #2145
      RandolpNolen
      Participant

      hey guys

      Heres my code>>>>

    • #3464
      GWILouisaxwzkla
      Participant

      What I might do is put a marker in between each question in the file so that one can be read at a time , like:

      A for loop is designed to

      a.)run only if the condition is false
      b.)run a set number of times
      c.)run at least once
      d.)run when there are no conditions

      @

      A while loop is designed to

      a.)run only if the condition is true
      b.) run a set number of times
      c.)run at least once
      d.)run when there are no conditions

      so that you can read up to the ‘@’ character , stop and get the answer and then continue. You could make the while loop read one word at a time ( stopping when you read ‘@’ ) and then get the answer.

    • #3465
      RandolpNolen
      Participant

      @dman wrote:

      What I might do is put a marker in between each question in the file so that one can be read at a time , like:

      A for loop is designed to

      a.)run only if the condition is false
      b.)run a set number of times
      c.)run at least once
      d.)run when there are no conditions

      @

      A while loop is designed to

      a.)run only if the condition is true
      b.) run a set number of times
      c.)run at least once
      d.)run when there are no conditions

      so that you can read up to the ‘@’ character , stop and get the answer and then continue. You could make the while loop read one word at a time ( stopping when you read ‘@’ ) and then get the answer.

      yeah but how to put it into coding??

    • #3466
      GWILouisaxwzkla
      Participant

      This version works with this file format:

      A for loop is designed to

      a.)run only if the condition is false
      b.)run a set number of times
      c.)run at least once
      d.)run when there are no conditions
      @
      A while loop is designed to

      a.)run only if the condition is true
      b.) run a set number of times
      c.)run at least once
      d.)run when there are no conditions
      @

      code :

      #include
      #include

      int main ( void )
      {

      int questionNum;
      char questions [ 80 ];
      char c; /*variable to hold character input by user*/
      char choice[2]; /*create character array*/
      int i = 0; /*initialize counter i*/
      FILE * pFile;
      char ch;
      pFile = fopen ( “c:\programs\data2.txt” , “r” );
      if ( pFile == NULL )
      {
      perror (“FILE COULD BE OPEN”);
      return 1;
      }

      ch = getc ( pFile );
      while ( ! feof ( pFile ) )
      {

      printf(“n___________________n”);
      printf(“n Question n”);
      printf(“___________________nn”);

      while ( ch != ‘@’)
      {
      putchar ( ch );
      ch = getc ( pFile );
      }/*end else*/
      printf( “nnENTER YOUR ANSWER HERE: “); /*prompts user to input answer*/
      c = getchar ();
      getchar ();
      choice [ i ++ ] = c;
      ch = getc ( pFile );
      printf ( “n press any ‘ENTER’ for next Questions: “);

      }
      printf ( “n answers: n” );
      int j = 0;
      while ( j < i )
      {
      putchar ( choice [ j ] ) ;
      printf ( “n” );
      j ++;
      }

      return 0;

      }

    • #3467
      RandolpNolen
      Participant

      yeah Tnx :P

Viewing 4 reply threads
  • You must be logged in to reply to this topic.