Welcome Guest | Sign in | Register

Home > C Programming > File Handling > Questions and Answers

Exercise:

Section 1

01. What are the files which are automatically opened when a C file is executed?
A. stdin B. stdin, stdout, stderr
C. stdout D. None of these

Answer and Explanation

Answer: stdin, stdout, stderr

Explanation:
stdin, stdout, stderr (standard input, standard output, standard error).

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
02. The statement that defines an input file handle called input_file, which is a pointer to type FILE, is
A. type input_file as FILE; B. FILE *input_file;
C. input_file FILE; D. *FILE input_file;

Answer and Explanation

Answer: FILE *input_file;

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
03. Using input_file, open the file results.dat for read mode.
A. input_file = "results.dat" opened as "r"; B. open input_file as "results.dat" for "r";
C. fopen( input_file, "results.dat", "r" ); D. input_file = fopen( "results.dat", "r" );

Answer and Explanation

Answer: input_file = fopen( "results.dat", "r" );

Explanation:
input_file = fopen( "results.dat", "r" );

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
04. Write C statements which tests to see if input_file has opened the data file successfully. If not, print an error message and exit the program.
A. Test 1
if( input_file == NULL ) {
printf("Unable to open file.\n");\
exit(1);
}
B. Test 2
if( input_file != NULL ) {
printf("Unable to open file.\n");\
exit(1);
}
C. Test 3
while( input_file = NULL ) {
printf("Unable to open file.\n");\
exit(1);
}
D. Cannot be determined

Answer and Explanation

Answer: Test 1
if( input_file == NULL ) {
printf("Unable to open file.\n");\
exit(1);
}

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
05. 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...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
06. Choose the file associated with input_file.
A. close input_file; B. fclose( input_file );
C. fcloseall(); D. input_file( fclose );

Answer and Explanation

Answer: fclose( input_file );

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
07. What is the stand for FIFO?
A. First in first out B. For inter first out
C. Frame in frame out D. None

Answer and Explanation

Answer: First in first out

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
08. What is a proper method of opening a file for writing as binary file?
A. FILE *f = fwrite( "test.bin", "b" ); B. FILE *f = fopenb( "test.bin", "w" );
C. FILE *f = fopen( "test.bin", "wb" ); D. FILE *f = fwriteb( "test.bin" );
E. FILE *f = fopen( "test.bin", "bw" );

Answer and Explanation

Answer: FILE *f = fopen( "test.bin", "wb" );

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
09. How do you include a system header file called sysheader.h in a C source file?
A. #include B. #incl "sysheader.h"
C. #includefile D. #include sysheader.h
E. #incl

Answer and Explanation

Answer: #include

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
10. Which one of the following is valid for opening a read-only ASCII file?
A. fileOpen (filenm, "r"); B. fileOpen (filenm, "ra");
C. fileOpen (filenm, "read"); D. fopen (filenm, "read");
E. fopen (filenm, "r");

Answer and Explanation

Answer: fopen (filenm, "r");

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum



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