Welcome Guest | Sign in | Register
File Handling - Discussion Page For Q.10659 | C Programming Questions and Answers | C Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > File Handling > Questions and Answers

Exercise:

Section 1

Q: Write C code which will read a line of characters (terminated by a \n) from input_file into a character array called buffer. NULL terminate the buffer upon reading a \n.
A. Example 1
int ch, loop = 0;
ch = fgetc( input_file );
while( (ch != '\n') && (ch != EOF) ) {
buffer[loop] = ch;
loop++;
ch = fgetc( input_file );
}
buffer[loop] = NULL;
B. Example 2
int ch, loop = 0;
ch = fgetc( input_file );
while( (ch = '\n') && (ch = EOF) ) {
buffer[loop] = ch;
loop--;
ch = fgetc( input_file );
}
buffer[loop] = NULL;
C. Example 3
int ch, loop = 0;
ch = fgetc( input_file );
while( (ch <> '\n') && (ch != EOF) ) {
buffer[loop] = ch;
loop++;
ch = fgetc( input_file );
}
buffer[loop] = -1;
D. Cannot be determined

Answer and Explanation

Answer:Example 1
int ch, loop = 0;
ch = fgetc( input_file );
while( (ch != '\n') && (ch != EOF) ) {
buffer[loop] = ch;
loop++;
ch = fgetc( input_file );
}
buffer[loop] = NULL;

Explanation:
There is no explanation...

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.