/* ç¬¬ï¼’ç¨®æƒ…å ±å‡¦ç†æŠ€è¡“者試験 å¹³æˆ4年度・秋期・åˆå¾Œ å•13 BohYoh Shibata PREPARATION */ #include <stdio.h> #include <string.h> void formout(char *, int); main() { char inbuf[256]; int indent; FILE *fp; indent = 0; fp = fopen("TEXT", "r"); while (fgets(inbuf, 256, fp) != NULL) { switch ( inbuf[0] ) { case '#': indent += 2; if (indent > 10) indent = 10; formout(inbuf+1, indent); break; case '@': indent -= 2; if ( indent < 0 ) indent = 0; formout(inbuf+1, indent); break; case '!': indent = 0; formout(inbuf+1, indent); break; case '-': formout(inbuf+1, indent); break; default: formout(inbuf, indent) ; break; } } fclose(fp); } void formout(char *inp, int indent) { char outbuf[82]; int i, inleng, cpleng; for (i = 0; i < indent; i++) outbuf[i] = ' '; inleng = strlen(inp); cpleng = 80 - indent; while ( inleng > 0 ) { if ( inleng > cpleng ) { strncpy(outbuf+i, inp, cpleng ); outbuf[80] = '\n'; outbuf[81] = '\0'; } else strcpy(outbuf+i, inp); fputs(outbuf, stdout); inp += cpleng ; inleng -= cpleng; } }