fopen - Open/Create filefopen() is a standard input output library function to open an existing file or create a new file.
ParametersIt takes two arguments. First argument is the path of the file as null terminated string. Second argument is the mode. There are largely three modes of opening a file. They are "read" ("r"), "write" ("w") and "append" ("a"). File can be in the form of "text" file or "binary" ("b") file.
Returnfopen returns a pointer to a FILE context structure which contains file descriptor and file buffer details. If path is incorrect or file does not exists or there are not enough permissions then fopen() may fail and a NULL pointer is returned.
Opening file for reading:Opening an existing file can be done in read mode. Read in text mode "r" or read binary "rb" can be other option
Creating a new File:Write mode is used to create a new file. If file is already there the file will be truncated to zero bytes and new content will be overwritten.
About our authors: Team EQA
You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.
Learn on Youtube