when i try to run the program to make it just tell me how many characters are in a file i get a segmentation fault...
Code:
//Compares upto 100 files, and decides which one has the most characters(bytes) and which has the most words.
#include <stdio.h>
#include <stdlib.h>
int i;
int main(int argc,char **argv)
{
int c,w,n,max_char[n],max_words[n],numtotal,numwords; //CAN'T DO THIS since you don't know n.
char most_words,most_chars;
FILE *f[n],*g; //CAN'T DO THIS since you don't know n.
n=0;
numtotal=0;
for (i=1;i <= argc;i++){
f[n]=fopen(argv[i],"r"); //CAN'T DO THIS since this is stupid. Use g=..., instead.
if(f[n]==NULL){ //CAN'T DO THIS since f still doesn't exist, and again should be g.
printf("Can't open %s \n",argv[i]);
exit(0);
break;
}
else{
fgetc(f[n]); //DITTO
while(c != EOF){
if(c==' '){
numwords++;
}
c=getc(f[n]); //DITTO
}
}
n++;
exit(1);
}
printf("%d",c);
}