The C program below will create a file , open the same file, and write in it.
/**
C program to create a file and write to same file
C program to open a file by Codebind.com
*/
#include <stdio.h>
int main()
{
int num;
FILE *fptr;
fptr = fopen("program.txt","w");
if(fptr == NULL)
{
printf("Error!");
return 1;
}
printf("Enter a number to save it in a file: ");
scanf("%d",&num);
fprintf(fptr,"%d",num);
fclose(fptr);
return 0;
}
/*
OUTPUT
Enter a number to save it in a file: 5555555555555555555555555555555555555555555
*/
Leave a Reply