Computer Science, asked by sabasabiha260, 4 months ago

2. Writing a Simple C program: (a) Write a simple C program to get inputs from a text file

Answers

Answered by maryamzafar915
1

Answer:

#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;

}

Similar questions