Fill This Form To Receive Instant Help
Homework answers / question archive / I have a C programming question for you, where I will be required to modify a C program that counts the characters of a ASCII text file
I have a C programming question for you, where I will be required to modify a C program that counts the characters of a
ASCII text file.
This is the code, which is provided.
#include <stdbool.h> #include <stdio.h> typedef unsigned char BYTE; int main(int argc, char *argv[]) { if (argc != 2) { printf("Usage: ./count INPUTn"); return 1; } FILE *file = fopen(argv[1], "r"); if (!file) { printf("Could not open file.n"); return 1; } int count = 0; while (true) { BYTE b; fread(&b, 1, 1, file); if (feof(file)) { break; } count++; } printf("Number of characters: %in", count); }
The question is asking to modify this code, where instead of counting the ASCII characters, we have to make
a program that counts UTF-8 characters in a file.
Here is the questions:
The program above counts the number of characters in a file, assuming the file is encoded as ASCII. Modify the program so that it counts the number of characters in a file encoded as UTF-8.