How do you read a character from a file in C?
A. getc()
B. readchar()
C. read()
D. getchar()
Answer: Option A
Solution (By Examveda Team)
The correct answer is A: getc()Let's break down why:
getc() is a standard C library function specifically designed to read a single character from a file stream.
It takes a file pointer (FILE*) as an argument and returns the character read (as an integer) or EOF if the end of the file is reached or an error occurs.
readchar() is not a standard C function for file input.
read() is a lower-level function (usually from the POSIX standard) used for reading a block of data from a file descriptor, not a single character.
getchar() reads a character from standard input (stdin), which is usually the keyboard, not from a file.
So, getc() is the correct function to use when you want to read a single character from a file in C.
Join The Discussion
Comments (1)
Related Questions on File Input Output
In C, which library is used for file operations such as reading and writing files?
A. stdio.h
B. iostream.h
C. fileio.h
D. files.h
Which function is used to open a file in C for writing?
A. fopen()
B. open()
C. writefile()
D. createfile()
What does 'FILE' represent in C when working with files?
A. A built-in data type for files
B. A file descriptor
C. A file pointer
D. A file structure
How do you check if a file was opened successfully in C?
A. Use the 'filestatus' variable
B. Check the return value of fopen()
C. Use the 'fileopen' function
D. Check the file's size

the ans is wrong getchar will be the answer