int main (int argc, char * argv[]) { char chr, action; int wc=0,lc=0, cc=0,state; FILE *fptr;// declaring file pointer action = *(*(argv+2));// de-referencing argv2 twice and action setting it as the var actong get the charecter argument from the user. if (argc < 3)// checking if given args { fprintf(stderr, "You must specify agument(s)\n\nMAN PAGE\n\narg1\t\targ2\n======================\n\nFilename\tw\nFilename\tl\nFilename\tc\n\n======================\n\nw: counts words in file;\nl: counts lines in file;\nc: count charecters in file.\n\n"); exit(EXIT_FAILURE); //can use this or a non zero value for exit failure } fptr=fopen(argv[1],"r"); // setting the output of fopen which returns a fie pointer to file pointer. if (fptr == NULL)//check if file exists because fopen returns a value of NULL if the file isn't there or if you don't have the file permssions. { fprintf(stderr,"No such file or directory\n"); exit(EXIT_FAILURE); } while((chr=fgetc(fptr))!=EOF) //declaring chr as the charecters in the file until the file is empty. { cc++; // increment for every char if (chr=='\n') lc++; // increment ofr every new line if (chr==' '||chr=='\t'||chr=='\n') wc++;// increment every word } switch(action)// controll statement for which action was chosen by user { case 'w': fprintf(stdout,"%d words\n",wc); break; case 'l': fprintf(stdout,"%d lines\n",lc); break; case 'c': fprintf(stdout,"%d charecters\n",cc); break; } return(0); }