Created
March 24, 2019 04:23
-
-
Save maehrm/44075f1ba2a49c91b6ee43f727b5ce7d to your computer and use it in GitHub Desktop.
平成20年度春期試験_基本情報午後問6(C)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#define MRNUM 50 /* 参考資料名の最大個数 */ | |
#define MRLNG 255 /* 参考資料名の最大文字数 */ | |
#define MARK '\\' /* 参考資料名の囲み文字 */ | |
void markup_reference(const char *, const char *); | |
void markup_reference(const char *in_filename, | |
const char *out_finename) { | |
FILE *ifp, *ofp; | |
char ch, ref_name[MRLNG + 1], | |
ref_name_tbl[MRNUM][MRLNG + 1]; | |
int i, ref_num = 0; | |
ifp = fopen(in_filename, "r"); | |
ofp = fopen(out_finename, "w"); | |
while ((ch = fgetc(ifp)) != EOF) { | |
if (ch != MARK) | |
fputc(ch, ofp); | |
else { | |
for (i = 0; (ref_name[i] = fgetc(ifp)) != MARK; i++); | |
ref_name[i] = '\0'; | |
for (i = 0; i < ref_num; i++) | |
if (strcmp(ref_name, ref_name_tbl[i]) == 0) | |
break; | |
if (i >= ref_num) { | |
strcpy(ref_name_tbl[ref_num], ref_name); | |
ref_num++; | |
} | |
fprintf(ofp, "[%d]", i + 1); | |
} | |
} | |
fprintf(ofp, "\n\nReferences\n"); | |
for (i = 0; i < ref_num; i++) | |
fprintf(ofp, "[%d] %s\n", i + 1, ref_name_tbl[i]); | |
fclose(ifp); | |
fclose(ofp); | |
} | |
int main(int argc, char *argv[]) { | |
if (argc != 3) { | |
printf("Usage: %s infile outfile\n", argv[0]); | |
return 1; | |
} | |
markup_reference(argv[1], argv[2]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
平成20年度春季基本情報午後問6 - Mae向きなブログ