Home › Forums › C Programming › C- help with Clear screen › Re: Re: C- help with Clear screen
October 22, 2008 at 10:09 pm
#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
@
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | #include <stdio.h> #include <stdlib.h> 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; } |