+ 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; }
1 Resposta
+ 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.
😀