bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

assignment-p-14_v2.c (864B)


      1 /*
      2  * Author  : Amit Dutta <amitdutta4255@gmail.com>
      3  * Date    : 12 Dec 2025
      4  * Repo    : https://github.com/notamitgamer/bsc
      5  * License : MIT License (See the LICENSE file for details)
      6  */
      7 
      8 /* Write a C program that opens its own source code file, reads its contents, and then prints
      9 the contents to the console. */
     10 
     11 #include <stdio.h>
     12 
     13 #define FILENAME "assignment-p-14_v2.c"
     14 
     15 int main()
     16 {
     17     FILE *code = NULL;
     18     char temp;
     19 
     20     code = fopen(FILENAME, "r");
     21     if (code == NULL)
     22     {
     23         printf("\nCould not open the source file: %s", FILENAME);
     24         return 1;
     25     }
     26 
     27     printf("\nReading file: %s", FILENAME);
     28     printf("\n========== %s ==========\n\n", FILENAME);
     29 
     30     while ((temp = fgetc(code)) != EOF)
     31     {
     32         printf("%c", temp);
     33     }
     34 
     35     printf("\n\n========== End of %s ==========\n", FILENAME);
     36 
     37     fclose(code);
     38 
     39     return 0;
     40 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror