Solved programming problem

How to Scan A Number From User and Save it in a Text File in C.

Source code

#include <stdio.h>

int main()

{

    int n;

    FILE *ptr; ///FILE type pointer

    printf("Please Enter A Value: ");

    scanf("%d",&n);

    ptr=fopen("output.txt","w"); ///create a text file and save value there

    fprintf(ptr,"Your Value: %d",n);

    fclose(ptr);

    return 0;

}

Output

1st Step:

Run the Program And Enter a value & Enter A Value:!!!

Please Enter A Value:13 

This text file will automatically create.

Join the discussion

Add your comment