I am brand new to all this and I can't get my program to read the file from input. Here is my code. It says segmentation fault (core dumped) I'm assuming because fp is not getting the file information. Can anyone help?
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#define getchar() getc(stdin)
FILE *fopen(const char *filename, const char *mode);
int main(int argc, char *argv[])
{
int i;
int count1, count2, count3;
FILE *fp;
char ch;
for(i=0; i<argc; i++)
{
count1=0; count2=0; count3=0;
fp=fopen(argv[i], "r");
fread(argv[i], sizeof(argv[i]), sizeof(argv[i]), fp);
while((ch=getc(fp))!=EOF)
{
if(isalpha(ch=getc(fp)))
count1++;
if(isspace(ch=getc(fp)))
count2++;
if((ch=getc(fp))=='\n')
count3++;
printf("The first file has %d characters, %d words, and %d lines\n"
, count1, count2, count3);
fclose(fp);
}
}
return 0;
}
]