What are Command line arguments? Learn syntax for using Command line arguments, programs on Command line arguments.
- 101. Write a program accept a file name from user and print content of that file
#include<stdio.h> int main(int argc, char *argv) { if ( argc != 2 ){ printf( "usage: %s filename", argv ); } else { FILE *file = fopen( argv, "r" ); if(file == NULL) printf("Could not open file\n"); else { int x; while((x=fgetc(file)) != EOF) printf( "%c", x ); fclose( file ); } } }