Program No : 37 :

Write a program in C to display the text from file using command line arguments(cat command in unix) ?

             program no  : 37
 purpose : display the text from file using command line arguments

#include<"stdio.h">
#include<"conio.h">

int main(argc,argv)
int argc;
char *argv[];

{
	FILE *fp;
    
	char ch;

	if(argc!=2)
	{
         printf("usage is wrong");
		 return;
	}

    fp=fopen(argv[1],"r");

	if(fp==NULL)
	{
		printf("file opening error");

		return;
	}

	for(fscanf(fp,"%c",&ch);feof(fp)==0;fscanf(fp,"%c",&ch))
	{
		
		printf("%c",ch);

		
	}

	 
	fclose(fp);

	getch();

}  



Back