In this article, you will be going to learn about create a file and enter data into that file with the help of a user in C programming.
Below we presenting, A program to create a file and enter data from the user in C
#include <stdio.h> #include <stdlib.h> int main() { char str[1000]; FILE *fptr; fptr=fopen("test.txt","w"); if(fptr==NULL) { printf("Error in opening file!"); exit(1); } printf("Input a sentence to the file:"); fgets(str, sizeof str, stdin); fprintf(fptr,"%s",str); fclose(fptr); printf("\n Data stored successfully\n"); return 0; }
Output:
Input a sentence to the file: Welcome to lingarajtechhub
Data stored successfully.
Join Our Community
Join our WhatsApp Group To know more About Programming Language tips, tricks and knowledge about programming and how to start learning any programming language.