#include <stdio.h>
#include <stdlib.h>
/* CRコードをカウントする。 */
int main(int argc, char *args[]) {
int ch;
int count = 0;
FILE *file;
if (argc == 2) {
file
= fopen(args
[1], "r"); if (file == NULL) {
}
} else if (argc > 2) {
printf("arguments are 0 or 1.\n"); return 0;
} else {
file = stdin;
}
while ((ch
= fgetc(file
)) != EOF
) { if (ch == 0x0D) { /* 残念でした! バイナリファイルとして開かないと検出できません! */
++count;
}
}
printf("Count CR Code (0x0D): %d\n", count
);
if (file != stdin) {
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCi8qIENS44Kz44O844OJ44KS44Kr44Km44Oz44OI44GZ44KL44CCICovCgppbnQgbWFpbihpbnQgYXJnYywgY2hhciAqYXJnc1tdKSB7CgkKCWludCBjaDsKCWludCBjb3VudCA9IDA7CglGSUxFICpmaWxlOwoJCglpZiAoYXJnYyA9PSAyKSB7CgkJZmlsZSA9IGZvcGVuKGFyZ3NbMV0sICJyIik7CgkJaWYgKGZpbGUgPT0gTlVMTCkgewoJCQlwZXJyb3IoTlVMTCk7CgkJCWV4aXQoRVhJVF9GQUlMVVJFKTsKCQl9Cgl9IGVsc2UgaWYgKGFyZ2MgPiAyKSB7CgkJcHJpbnRmKCJhcmd1bWVudHMgYXJlIDAgb3IgMS5cbiIpOwoJCXJldHVybiAwOwoJfSBlbHNlIHsKCQlmaWxlID0gc3RkaW47Cgl9CgkKCXdoaWxlICgoY2ggPSBmZ2V0YyhmaWxlKSkgIT0gRU9GKSB7CgkJaWYgKGNoID09IDB4MEQpIHsgLyog5q6L5b+144Gn44GX44Gf77yBIOODkOOCpOODiuODquODleOCoeOCpOODq+OBqOOBl+OBpumWi+OBi+OBquOBhOOBqOaknOWHuuOBp+OBjeOBvuOBm+OCk++8gSAqLwoJCQkrK2NvdW50OwoJCX0KCX0KCQoJcHJpbnRmKCJDb3VudCBDUiBDb2RlICgweDBEKTogJWRcbiIsIGNvdW50KTsKCQoJaWYgKGZpbGUgIT0gc3RkaW4pIHsKCQlmY2xvc2UoZmlsZSk7Cgl9CgkKCXJldHVybiAwOwp9Cg==