C Saved Program: serene-af

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


#include <stdio.h>
#include <stdlib.h>

int main( int argc, char *argv[] )  {
    FILE *fp;
    char* file_name;
    char ch;

    if(argv[2] != NULL)
    {
        file_name = argv[2];
    }
    else
    {
        perror("File doesn't exist\n");
    }

    fp = fopen(file_name,"r");

    if( fp == NULL )
    {
      perror("Error while opening the file ");
      exit(EXIT_FAILURE);
    }
   
    while( ( ch = fgetc(fp) ) != EOF )
      printf("%c",ch);
 
    fclose(fp);
    return 0;
}
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs