bsc

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

root / semester_1 / assignment-primary / assignment-p-14_v2.c

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


      1 /* Write a C program that opens its own source code file, reads its contents, and then prints
      2 the contents to the console. */
      3 
      4 #include <stdio.h>
      5 
      6 #define FILENAME "assignment-p-14_v2.c"
      7 
      8 int main()
      9 {
     10     FILE *code = NULL;
     11     char temp;
     12 
     13     code = fopen(FILENAME, "r");
     14     if (code == NULL)
     15     {
     16         printf("\nCould not open the source file: %s", FILENAME);
     17         return 1;
     18     }
     19 
     20     printf("\nReading file: %s", FILENAME);
     21     printf("\n========== %s ==========\n\n", FILENAME);
     22 
     23     while ((temp = fgetc(code)) != EOF)
     24     {
     25         printf("%c", temp);
     26     }
     27 
     28     printf("\n\n========== End of %s ==========\n", FILENAME);
     29 
     30     fclose(code);
     31 
     32     return 0;
     33 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror