C言語なら私に聞いてYO! 49
■ このスレッドは過去ログ倉庫に格納されています
0505デフォルトの名無しさん
NGNG#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(int argc, char * argv[]) {
char s[512], *p;
FILE *ifp, *ofp;
if (argc != 3) {
fputs("usage: hoge <in> <out>\n", stderr);
return 0;
}
ifp = fopen(argv[1], "rb"); ofp = fopen(argv[2], "wb");
if (!ifp || !ofp) {
perror(NULL);
return 3;
}
while (fgets(s, sizeof(s), ifp)) {
if (p = strchr(s, '#')) *p = '\0';
else if (p = strchr(s, '\n')) *p = '\0';
if (isdigit(*s)) {
int i = atoi(s);
fwrite(&i, sizeof(i), 1, ofp);
}
else
fputs(s, ofp);
fputc('\n', ofp);
}
fclose(ofp); fclose(ifp);
return 0;
}
■ このスレッドは過去ログ倉庫に格納されています