to get a string, which function is safe to use?
Correct!
fgets( )
Because, In fgets() we can specify the size of the buffer into which the string supplied will be stored
Which of the following is true:
gets() doesn’t do any array bound testing and should not be used.
Files stdin, stdout, and stderr are already open by the sytem for you to use.
True
What does the following C statement mean?
scanf(“%4s”, str);
Read maximum 4 characters from keyboard.
What is the purpose of “rb” in fopen() function used below in the code?
open “source.txt” in binary mode for reading
Which of the following statement is correct about the program?
#include
The code counts number of lines in the file
The FILE pointer contains all information about a file.
Yes
Which of the following operations can be performed on the file “NOTES.TXT” using the below code?
FILE *fp;
fp = fopen(“NOTES.TXT”, “r+”);
Read and Write
a binary file can not be read correctly by formatted input function fscanf( ).
True
When fopen() fails to open a file it returns
NULL
Suppose that a file contains the line “I am a boy\n”. Then on reading this line into the array of char str using fgets(). What will str contain?
“I am a boy\n\0”
function fopen() is used for opening a file.
True
Why should you close a file by calling fclose( ), if the file is not used any more?
since the number of open files is limited
if the program crashes, the data in the file buffer is lost.
The EOF is equivalent to
-1
Input/output function prototypes and macros are defined in which header file?
stdio.h
Any file with extension name “.txt” is a text file.
False
Point out the correct statements about the program?
#include
The code writes strings that are read from the keyboard into a file.
What is the return type of getchar()?
int
To print out a and b given below, which of the following printf() statement will you use?
#include
printf(“%f %lf”, a, b);
To print a float value, %f is used as format specifier.To print a double value, %lf is used as format specifier.
What will be the output of the program if value 25 given to scanf()?
#include
1