#define WINDOWS_OS !defined(__linux__) && !defined(__unix__) && !defined(__APPLE__)
#if WINDOWS_OS
# include <fcntl.h>
# include <io.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#if WINDOWS_OS
# if defined(__BORLANDC__)
# define Setmode(f,t) setmode((f),(t))
# define Fileno(f) fileno(f)
# define O_Binary O_BINARY
# else
# define Setmode(f,t) _setmode((f),(t))
# define Fileno(f) _fileno(f)
# define O_Binary _O_BINARY
# endif
#else
# define Setmode(f,t) 0
#endif
#define ArrLen(arr) (sizeof(arr) / sizeof(arr[0]))
/* CRコードをカウントする。 */
int main(int argc, char *args[]) {
int ch;
int count = 0;
char data[100];
int i, sz, md;
FILE *file;
if (argc == 2) {
file
= fopen(args
[1], "rb"); if (file == NULL) {
}
} else if (argc > 2) {
printf("arguments are 0 or 1.\n"); return 0;
} else {
md = Setmode(Fileno(stdin), O_Binary);
if (md == -1) {
}
file = stdin;
}
while ((sz
= fread(data
, sizeof(data
[0]), ArrLen
(data
), file
)) != 0) { for (i = 0; i < sz; ++i) {
if (data[i] == 0x0D) {
++count;
}
}
}
printf("Count CR Code (0x0D): %d\n", count
);
if (file != stdin) {
}
return 0;
}
I2RlZmluZSBXSU5ET1dTX09TICFkZWZpbmVkKF9fbGludXhfXykgJiYgIWRlZmluZWQoX191bml4X18pICYmICFkZWZpbmVkKF9fQVBQTEVfXykKCiNpZiBXSU5ET1dTX09TCiMgIGluY2x1ZGUgPGZjbnRsLmg+CiMgIGluY2x1ZGUgPGlvLmg+CiNlbmRpZgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPHN0ZGxpYi5oPgoKI2lmIFdJTkRPV1NfT1MKIyAgaWYgZGVmaW5lZChfX0JPUkxBTkRDX18pCiMgICAgZGVmaW5lIFNldG1vZGUoZix0KSBzZXRtb2RlKChmKSwodCkpCiMgICAgZGVmaW5lIEZpbGVubyhmKSAgICBmaWxlbm8oZikKIyAgICBkZWZpbmUgT19CaW5hcnkgICAgIE9fQklO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