File Operation in C
February 8, 2020
Below is a simple C program to perform file operation –
include <stdlib.h>
main() {
FILE * file_source
char * file_name = (char*) malloc (sizeof (char)* 13);
char * file_content= (char*) malloc (sizeof (char)* 100);
printf("Enter File Name>");
gets (file_name);
file_source = fopen(file_name, "r+");
if(file_source == NULL) {
printf("File doesn't exist");
}
else{
while ( fgets (file_content, 100, file_source) != NULL){
printf("%s",file_content);
}
fclose(file_source);
}
}