belongs to collection: File handling in C
create a file using fopen in C
In the below code, I am creating a text file using the fopen() function.
#include <stdio.h> #include <stdlib.h> int main() { FILE *fp = NULL; //create a text file fp = fopen ("aticleworld.txt", "w"); if(fp == NULL) { printf("File is not created\n"); exit(1); } else { printf("File is created\n"); } //close the file fclose(fp); return 0; }
Output:
If fopen() create file successfully, the text file will be created in the same folder where you have saved your code. Like the below image.
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
In the below code, I am creating a text file using the fopen() function.
Output:
If fopen() create file successfully, the text file will be created in the same folder where you have saved your code. Like the below image.
![](data:image/webp;base64,UklGRlgaAABXRUJQVlA4IEwaAABQcQCdASqAApEAPolEnUqlI6Kho9YpkKARCWlu4XHg83WG2UfTX9M7Zv7//Vv218+/Dz5nz2c89o38p+3n7b/E+5z9r/z3g/7+/7n+y+wL7C/1O9U6f/j/1z9gL1T+b/7T/F/vP723o3+N9Avyn+r/773AP5H/VP9368f8DwPvsf+o9gH+S/1H/if4j8tPj6/7P9d56/0f/Hf+b/TfAT/MP7F/3f7/2u/3e9pH93RjLnQnnytZDd+VsRXOiUgb7tAqrfq8W1iFGCFqxzs2oni0j8mfn6aJDYiKUBGm6gbsWUkn5qWnwUqGyqGQgJUcgvmpFtxBh8jLcmqfEH1qrGLFAUqDuKuJhj01cX9Y7FLc/7vJo0MemriJlbmjxKD8bLvZANgavTVE215nZl9S5lQ2j8FKhmlQuQl6ZA02L6tEzvI4p66DllxvLYuvM/Q5hazxI/OsZLIn+42H9D9xx7wuQiZ/ecxCvxxhxgoQMiBK3weZ60oVDRoEQ2VQyEBKa1JQ+UXLZDBrSnqOCkT8AvhA5UYEoXbrXREstOXdx9sjy1ix9SV5Tc56lCWjsXdI6Jr9XLlBRyJ1ohw2MmLGZtbX4kpl+V6yOMjUXwKl2llyLDRy9ovdeWIksTmEjkjmL92zTFriVeZUewZ6dGZROjKT6EZ4a8pr2gUj0N8+KD7VKYempW5hfVvTog9+pEXlNznqUEKiHvN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sxhGC67IVbpA6Y/FbcxslPiyG7/PkDnrmMrhOAUReeaHjfLnWiFQjEKAAcCbdy7yfjPq4MIn46FS32vioeJOgQNcnzzvwMdlYwdRpTFUPmo0qqB71p3txB+96eDHYmJEz2mqgQXoQoloFZqjwZ0KdKfJciZuneu1j26XDDPUgFA3B+acSO8Tb7K4OxUrDrY1G+Aw0cxSARgpsxL5IY63wnrPI0mU3iZrtkKVVnpLvICiMazYowL2GNXv1myVY8j4J03Qg/Hny5U2uUs+2WCqfrYusC4qUESOtxSViqAQDwfcjNAK3hPrUqsBb4Ip7DaIdIN+KQQTI0CnXfJ8FBrPNETgRHwrnGqatDCUz6lac7iBVWhF9kKWRt9MrrHnDsfnzFOp8v/qwaSQ8C13tPV3BB9FT1ni+x+vDXpha/8TSnG0KP4IhOqgniVIOMzhKa4GY0OiQLp3g34nYyTKnsNiKlkMCG9WrSYCsm2qyQlkSCDF0wFyz31wbnZCezVA0xGMcbTAeVBlwcWLxcfHTxxAFCNfXx13OedB9/vkutY1zQ3d5cdZyCIDSv4TKQUUfSmsw0Xuj7IoUBdBV78/JQT++Mwgj0A6kun9RBRej5TMEX15KFEW5YjoVuY5eC0KJyCHy5qZeq7Ywbv6DjW+wBP4jw0LUCxZy5YEu5Bzno7S1gDf2qev8CrT1dAAAAAAAA=)
need an explanation for this answer? contact us directly to get an explanation for this answer