The questions asks to count number of characters and lines and print them from any number of files processed.. i dont seem to get anything useful from my program and i need ur help to fix it..its simialar to the cat command in linux but it should tell the number of characters and lines
Code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]){
int i;
FILE *fp;
char ch;
int count;
int lines;
count=0;
lines=0;
char S[100];
if(argc == 1){
fgets(S,100,stdin);
fputs(S,stdout);
}
for(i=1;i<argc;i++){
if((fp=fopen(argv[i],"r"))==NULL){
fprintf(stderr,"ERROR OPENNING FILE");
}
}
while(( ch =fgetc(fp)) != EOF){
count++;
if(ch == '\n')
lines++;
}
}
printf("Number of characters is %d\n",count);
printf("Number of lines is %d\n",lines);
fclose(fp);
}
}