C Open A File And Write Stuff

[Solved] C Open A File And Write Stuff | Vb - Code Explorer | yomemimo.com
Question : Read Write in File in C language

Answered by : muhammad-abdullah-jxze1et1y350

//////WRITE
#include <stdio.h>
#include <stdlib.h>
int main()
{ int num; FILE *fptr; // use appropriate location if you are using MacOS or Linux fptr = fopen("C:\\program.txt","w"); if(fptr == NULL) { printf("Error!"); exit(1); } printf("Enter num: "); scanf("%d",&num); fprintf(fptr,"%d",num); fclose(fptr); return 0;
}
//////READ
#include <stdio.h>
#include <stdlib.h>
int main()
{ int num; FILE *fptr; if ((fptr = fopen("C:\\program.txt","r")) == NULL){ printf("Error! opening file"); // Program exits if the file pointer returns NULL. exit(1); } fscanf(fptr,"%d", &num); printf("Value of n=%d", num); fclose(fptr); return 0;
}

Source : | Last Update : Mon, 03 Oct 22

Answers related to c open a file and write stuff

Code Explorer Popular Question For Vb