In C Programming[from refixed coder], whenever we write code regarding file handling, some files will create and save( if it is not present ) during write mode opening.

Here a simple program, we will write a program where it will just take one number and it will store in a file.

CODE:

#include<stdio.h> #for taking input and printing output
//from refixed coder
int main()
{
    int num;
    FILE *filepointer=fopen("filename.txt","w");
    printf("\n ENTER AN INTEGER: ");
    scanf("%d",&num);
    fprintf(filepointer,"%d\n",num);
    printf("\n %d HAS BEEN WRITTEN SUCCESSFULLY.\n",num);
    fclose(filepointer);
    return 1;
}

CODE IMAGE:



BEFORE COMPILING PROGRAM, ONLY ONE FILE PRESENT I.E. C FILE IN WHICH WE HAVE WRITTEN CODE AND SAVE THIS FILE AS NAME: FILE.TXT 


IMAGE:



After running this file.c, there two files have created. One is file.exe file and another is filename.txt ( filename.txt file has created because of we have given a file name in fopen("filename.txt","w"); Here "w" for write mode opening.)

Here as it is filename.txt did not present, for this reason during "w" write mode opening, this file will create.

IMAGE:



REMEMBER: our program path is :

F:\CODEBLOCKS\My Desire\C AND CPP\C PROGRAM\FILE HANDLING


If you notice very carefully, at the same directory (i.e in the hard disk, same hard disk's partition's specific folder ) file has created and has saved in file handling.

Now, if we run this program and then give some integer input. 

IMAGE:



After that, if we open the file ( filename.txt), if we found that same integer present in this textfile then we will surely confirm that at the same directory( where c file will present) in c, the file will create and save.

NOW WE WILL OPEN FILENAME.TXT FILE AND WE WILL CHECK:



Check-in 3rd picture, we have given 78 as an interger. With the help of file handling, using fprintf, we have written 78 in filename.txt.


SO, NOW WE CONFIRM THAT WHERE WE WILL CREATE C FILE, IN FILE HANDLING, FILE WILL CREATE AND SAVE AT THE SAME LOCATION.

If you face any problem to understand, feel free to comment below. We will clear your confusion as soon as possible.