Skip to content

Instantly share code, notes, and snippets.

@maehrm
Last active April 22, 2018 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maehrm/797852c82f33c719158a9f4e243034fe to your computer and use it in GitHub Desktop.
Save maehrm/797852c82f33c719158a9f4e243034fe to your computer and use it in GitHub Desktop.
平成30年度春期基本情報技術者試験 午後 問9 プログラム2
#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;
}
@maehrm
Copy link
Author

maehrm commented Apr 22, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment