I'm kind of new to programming, anyway I wanted to write a program to count the size of a file. It detects the end of file earlier than expected.
I can't seem to find something wrong.Please take a look and tell me.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ARXEIO1 "C:SIZE_TO_FIND.DAT"
void synartisi_1(int *bytes,char *xar,FILE *arxeio);
int main(void)
{
FILE *arxeio1;
char xar;
int bytes = 0;
int r = 0;
arxeio1 = fopen(ARXEIO1,"r");
synartisi_1(&bytes,&xar,arxeio1);
while ( feof(arxeio1) == 0 )
{
synartisi_1(&bytes,&xar,arxeio1);
}
fclose(arxeio1);
return 0;
}
void synartisi_1(int *bytes,char *xar,FILE *arxeio)
{
(*bytes)++;
fgetc(arxeio);
if ( (*bytes)%100 == 0 )
{
printf("\nUntil now %d bytes %.3f Kb %.3f Mb", (*bytes) , ((*bytes)/1024.0) , (((*bytes)/1024.0)/1024.0) );
}
}