/*
第2種情報処理技術者試験 平成7年度・春期・午後 問7
BohYoh Shibata PREPARATION
*/
#include <stdio.h>
#include <string.h>
#define LLENG 60
char chtbl[] = { "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789,." };
main()
{
FILE *ifp, *ofp;
long psiz;
int p, s;
char pch, tch, tbuf[LLENG+2];
ifp = fopen("txt_file", "r");
ofp = fopen("prg_file", "wb");
fscanf(ifp, "%ld\n", &psiz);
while ( psiz > 0 ) {
fgets(tbuf, sizeof(tbuf), ifp);
p = 0;
while(p < LLENG && psiz > 0 ) {
tch = strchr(chtbl, tbuf[p++]) - chtbl;
pch = tch << 2;
for (s = 4; s < 9 && psiz > 0 ; s += 2) {
tch = strchr(chtbl, tbuf[p++]) - chtbl;
pch |= tch >> (8 - s);
fputc(pch, ofp);
psiz--;
pch = tch << s;
}
}
}
fclose(ifp);
fclose(ofp);
}