/* Program#file2.c Example of parameter passing using argc and argv */ /*Search specified file for specified character. */ #include #include void main(int argc, char *argv[]) { FILE *fp; /* file pointer */ char ch; /* see if correct number of command line arguments */ if(argc !=3) { printf("Usage: find <filename> <ch>\n"); exit(1); } /* open file for input */ if ((fp = fopen(argv[1], "r"))==NULL) { printf("Cannot open file \n"); exit(1); } /* look for character */ while ((ch = getc(fp)) !=EOF) /* where getc() is a */ if (ch== *argv[2]) { /*function to get one char*/ printf("%c found",ch); /* from the file */ break; } fclose(fp); }