luc095.c (1061B)
1 /* 2 * Author : Amit Dutta <amitdutta4255@gmail.com> 3 * Date : 08 Feb 2026 4 * Repo : https://github.com/notamitgamer/bsc 5 * License : MIT License (See the LICENSE file for details) 6 */ 7 8 /* Write a program that can read a file and display its contents. The file name should be supplied as a command-line argument. 9 */ 10 /* Let Us C, Chap- 20 (More Issues In Input/Output), Qn No.: A(a) */ 11 12 /* This file is auto-generated by a bot. */ 13 /* This code is not compiled; it is for reference only. */ 14 15 16 #include <stdio.h> 17 #include <stdlib.h> 18 #include <string.h> 19 #include <ctype.h> 20 21 int main(int argc, char *argv[]) 22 { 23 FILE *fp; 24 char ch; 25 26 /* Check if file name is provided */ 27 if (argc != 2) 28 { 29 printf("Usage: %s <filename>\n", argv[0]); 30 exit(1); 31 } 32 33 fp = fopen(argv[1], "r"); 34 if (fp == NULL) 35 { 36 printf("Error: Cannot open file '%s'\n", argv[1]); 37 exit(2); 38 } 39 40 /* Read and display contents */ 41 while ((ch = fgetc(fp)) != EOF) 42 { 43 printf("%c", ch); 44 } 45 46 fclose(fp); 47 return 0; 48 }