Last active
April 22, 2018 20:16
-
-
Save maehrm/797852c82f33c719158a9f4e243034fe to your computer and use it in GitHub Desktop.
平成30年度春期基本情報技術者試験 午後 問9 プログラム2
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 <stdlib.h> | |
#define listLen 32 /* 入力レコードの最大文字数 + 2('\n', '\0') */ | |
void outListG(char *listFile) { | |
FILE *inFile; | |
char inBuf[listLen]; | |
long value, valueMax; | |
char graph[] = "*************************"; | |
inFile = fopen(listFile, "r"); | |
valueMax = 0; | |
while (fgets(inBuf, listLen, inFile) != NULL) { | |
value = atol(inBuf + 21); | |
if (value > valueMax) { | |
valueMax = value; | |
} | |
} | |
fclose(inFile); | |
inFile = fopen(listFile, "r"); | |
while (fgets(inBuf, listLen, inFile) != NULL) { | |
value = atol(inBuf + 21); | |
printf("%.30s |%s\n", | |
inBuf, &graph[25 - 25 * value / valueMax]); /* α */ | |
/* %.30s はレコードの先頭からの30桁(\nの直前まで)を出力する */ | |
} | |
fclose(inFile); | |
} | |
int main(int argc, char *argv[]) | |
{ | |
outListG(argv[1]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://maehrm.hatenablog.com/entry/2018/04/23/051536