Explain the code given in description | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Explain the code given in description

#include <stdio.h> int main() { FILE *fptr; fptr = fopen("myfile.txt", "w"); if (fptr == NULL) { printf("Error opening file."); return -1; } fclose(fptr); return 0; }

12th Jun 2019, 12:07 AM
Mehedi Hasan
Mehedi Hasan - avatar
1 Answer
+ 6
This code is about file handling in C. A file pointer is declared in line 3. Then a file named myfile.txt is opened in write mode using fopen method. If file exist it will start writing to file after deleting all the data. If File does not exist then it will create a new file with same name. if statement checks wether fptr(file pointer) is blank or not if it is blank then it will show an error "Error opening file ". fclose(fptr) closes the opened file named fptr. That's all about this code. Hope this will help. 😀
12th Jun 2019, 2:24 AM
Deepak Kumar
Deepak Kumar - avatar