Lab Task 1 [30] Write a program in C which accepts a file name on command line from the user. Your program should then r

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

Lab Task 1 [30] Write a program in C which accepts a file name on command line from the user. Your program should then r

Post by answerhappygod »

Lab Task 1 30 Write A Program In C Which Accepts A File Name On Command Line From The User Your Program Should Then R 1
Lab Task 1 30 Write A Program In C Which Accepts A File Name On Command Line From The User Your Program Should Then R 1 (78.51 KiB) Viewed 51 times
Lab Task 1 [30] Write a program in C which accepts a file name on command line from the user. Your program should then read the file line by line till end of file and displays the longest line in the file on the console. You are allowed to use C string built in functions in this part. Strictly follow the incomplete code skeleton given below. Everyone must use the same function/s provided in the skeleton. A zero grade will be awarded in this task if you deviate from the given code skeleton. #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { 710 num args if(argc != 2) { printf("This program needs a text file as argument\n"); exit(0); } // your logic goes here return 0; } Sample Run Suppose myfile is a text file that you can create at your own and place it in the same folder where the .c file for your code resides. Contents of myfile are as shown: Hello class. This is a test file for lab1. Compiler Construction is a fun course. You should run your program as follows: $ ./lablTaskl myfile Longest line in the file: Compiler Construction is a fun course.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply