C language simple input and output. I need a program, that prints out the input from the keyboard to a specific file. T

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

C language simple input and output. I need a program, that prints out the input from the keyboard to a specific file. T

Post by answerhappygod »

C language simple input and output. I need aprogram, that prints out the input from the keyboard toa specific file. This code let me to enter the input but I don'tsee the saved output in a created file. Why? How to fix it?
#include<stdio.h>#include<stdlib.h>
int main(void){ char ch[100]; FILE* fp; if(!(fp = fopen("RandomFile1.txt", "r"))){ printf("\aCannot open thefile.\n"); exit(100); } while(fgets(ch, sizeof(ch), stdin)){ fputs(ch, fp); } fclose(fp); return 0;}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply