Ultimate Guide to Using the Show Command in C

Show Command in C

To display the contents of a file, we have the ‘type’ command in DOS and ‘cat’ to display command in unix.

    c:\> show command

Program to demonstrate show command in C

#include<stdio.h>
void main(int argc, char *argv[])
{
  FILE *fp;
  char ch;
  fp=fopen(argv[1], "r");
  if(fp == NULL)
  {
      printf("File not found");
      return;
  }
  if(argc != 2)
  {
     printf("\n Invalid no of arguments");
     return;
  }
      while(ch= getc(fp)) !=EOF)
          putchar(ch);
      fclose(fp);
}

Save this program as ‘show.c’ and then compile and run it to get ‘show.exe’. To run this executable file, go to DOS prompt and type

D:\sub>show myfile.txt

Now, it will display the contents of myfile.txt file. If we type,

D:\sub>show

Then it will display, ‘File not found’.

$cc show.c

Now, an executable file a.out will be created.

$mv a.out show

To display the contents of myfile.txt use the command as:

show mytext.txt
Naveed Tawargeri
 

Hi, I'm Naveed Tawargeri, and I'm the owner and creator of this blog. I'm a Software Developer with a passion for Programming.