在这个程序中,我想打印出文件中不同字符的实例。输出将包含三个变量,出现次数、字母的十六进制和字母本身。有人可以帮我弄这个吗?我被困住了!
Results of program should be something like this:
10 instance of character 0x4s (O)
10 instance of character 0x51 (W)
10 instance of character 0x51 (Y)
2 instances of character 0x65 (a)
18 instances of character 0x67 (c)
16 instances of character 0x81 (d)
//here is my program.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const char FILE_NAME[] = "input.txt";
int main(argc, *argv[]) {
char temp;
char count[255];
FILE *in_file;
int ch;
fp = fopen(FILE_NAME, "r");
if (in_file == NULL) {
printf("Can not open %s \n", FILE_NAME);
exit(0);
}
while (!feof(fp)) {
ch = fgetc(fp);
if(strchr(count, ch)!= NULL)
{
}
}
printf("%d instance of character (%c)", count);
fclose(in_file);
return (0);
}