Home › Forums › C Programming › C- help with Clear screen
- This topic has 4 replies, 2 voices, and was last updated 12 years, 3 months ago by
RandolpNolen.
- AuthorPosts
- October 20, 2008 at 11:55 pm #2145
RandolpNolen
Participanthey guys
Heres my code>>>>
12345<br /><br />kkk<br /><br /> - October 21, 2008 at 8:25 pm #3464
GWILouisaxwzkla
ParticipantWhat 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 conditionsso 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.
- October 21, 2008 at 11:43 pm #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 conditionsso 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??
- October 22, 2008 at 10:09 pm #3466
GWILouisaxwzkla
ParticipantThis 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 toa.)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
#includeint 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;
}
- October 22, 2008 at 11:40 pm #3467
RandolpNolen
Participantyeah Tnx :P
- AuthorPosts
- You must be logged in to reply to this topic.