Lab Task 2 [40] 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 2 [40] 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 2 40 Write A Program In C Which Accepts A File Name On Command Line From The User Your Program Should Then R 1
Lab Task 2 40 Write A Program In C Which Accepts A File Name On Command Line From The User Your Program Should Then R 1 (76.01 KiB) Viewed 46 times
Lab Task 2 [40] 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 NOT allowed to use C string built in functions in this part. Here you are required to write your own function/s that can compute the length of the line passed to it as input argument. 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> int get_length (char*); int main(int argc, char *argv[]) //check number of args if(arge != 2) printf("This program needs a text file as argument\n"); exit(0); } //your logic goes here return 0; } int get length (char *s) } void cpy_strings (char *destination, char *source) 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: $ ./lab1 Task2 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