commit 470c684c82dc071c148283859695235741e3ff54
parent 554b0b06e455280fcc6c1402505f3eeb53f21434
Author: qorg11 <qorg@vxempire.xyz>
Date: Sat, 2 Jan 2021 14:15:42 +0100
Make wc read binary data by using fread() instead of fgetc()
Diffstat:
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/wc.c b/src/wc.c
@@ -35,16 +35,16 @@ wc(const char *filename, struct wc_values *data)
}
char c;
char a;
+ char buf;
int newlines, spaces, bytes = 0;
newlines = spaces = bytes = 0;
- while((c = fgetc(file)) > 0) {
- a = c;
- if(!isascii(c))
- a = toascii(c);
+ while((c = fread(&buf,1,1, file)) > 0) {
+ if(!isascii(buf))
+ a = toascii(buf);
bytes++;
- if(a == '\n')
+ if(buf == '\n')
newlines++;
- if(isspace(c))
+ if(isspace(buf))
spaces++;
}
data->bytes = bytes;