#include #include #include int main(int argc, char *argv[] ) { char filename[50]; printf("E

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

#include #include #include int main(int argc, char *argv[] ) { char filename[50]; printf("E

Post by answerhappygod »

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(int argc, char *argv[] )
{
char filename[50];
printf("Enter the Filename : ");
scanf("%s",&filename);
char line[50];
FILE *fp = fopen( filename, "r");
if (fp == NULL)
{
printf("File opening Unsuccessful\n");
exit(1);
}
else{
printf("File has been open Unsuccessfully\n");
}
while (fgets(line , 30 , fp)
!= NULL)
{
printf(line);
}
fclose(fp) ;
return 0;
}
Write a C program that t expands on the C code
above by reading each of the lines in the file and
displays all the lines read from the file on the screen before
closing it.
The code for this will occur before closing file.
Your program must then output the number of lines in the
file.
To test program, create a text file with at least 5 lines
of text (can be of anything). Use text editor such as
notepad++ to create said text file
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply