ExamVeda
Login
Home
This question belongs to C Program File Input Output
File Input Output
?

How do you read a character from a file in C?

Answer & Solution
Correct Answer: Option A
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.
Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
Piyush Tanwani
Piyush Tanwani 1 year ago
the ans is wrong getchar will be the answer