1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <stdio.h>
#include <stdlib.h>
void filestats(FILE*,float*,float*,float*);
int main (void)
{
float nl=0,nw=0,nc=0;
float *nl_ptr,*nw_ptr,*nc_ptr; //THIS IS WHERE MY TROUBLE IS
nl_ptr=&nl;nw_ptr=&nw;nc_ptr=&nc; //THIS IS WHERE MY TROUBLE IS
FILE *fin=fopen("filestatsin.txt","r");
filestats(fin,&nl,&nw,&nc); //THIS IS WHERE MY TROUBLE IS
printf("chars: %d words: %d lines:%d",nc,nw,*nl_ptr); //THIS IS WHERE MY TROUBLE IS
system("pause");
return 0;
}
void filestats(FILE * fin,float *nl_ptr,float *nw_ptr,float *nc_ptr)
{
char c;
int l=0,w=0,c2=0;
while(fscanf(fin,"%c",&c)!=EOF){
printf("%c",c);
if((c=='a')||(c=='A')||(c=='b')||(c=='B')||(c=='c')||(c=='C')||(c=='d')||(c=='D')||(c=='e')||(c=='E')||(c=='f')||(c=='F')||(c=='g')||(c=='G')||(c=='h')||(c=='H')||(c=='i')||(c=='I')||(c=='j')||(c=='J')||(c=='k')||(c=='K')||(c=='l')||(c=='L')||(c=='m')||(c=='M')||(c=='n')||(c=='N')||(c=='o')||(c=='O')||(c=='p')||(c=='P')||(c=='q')||(c=='Q')||(c=='r')||(c=='R')||(c=='s')||(c=='S')||(c=='t')||(c=='T')||(c=='u')||(c=='U')||(c=='v')||(c=='V')||(c=='w')||(c=='W')||(c=='x')||(c=='X')||(c=='y')||(c=='Y')||(c=='z')||(c=='Z')){
c2++;
}else if((c==' ')){
w++;
}else if(c=='\n'){
l++;
}
}
*nw_ptr=(float)w+(float)l; //THIS IS WHERE MY TROUBLE IS
*nl_ptr=(float)l; //THIS IS WHERE MY TROUBLE IS
*nc_ptr=(float)c2; //THIS IS WHERE MY TROUBLE IS
printf("chars: %d words: %d lines:%d",c2,w+l,l);
system("pause");
return;
}
|