/* Ptt 大學聯招榜單 parse 程式 */
#include <stdlib.h>
#include <stdio.h>
int main()
{
FILE *fp = fopen("4.dat","r");
char clas[100],clas1[100],buf[100],*ch,*po,a;
ch = buf;
while(fscanf(fp,"%s",ch)==1)
{
if(*ch>='0' && *ch<='9' )
{
a = *ch;
*ch = '\0';
while (po = strstr(buf, " "))
{
*po = 0;
strcpy(po,po+2);
}
if(buf[5]>='0' && buf[5]<='9' && (buf[6]<'0' || buf[6]>'9'))
/* name */
{
printf("%-20s%-15s%s\n",buf,clas1,clas);
}
else if(buf[1] >='0' && buf[1] <='9')
{ /* class */
strcpy(clas,buf);
}
else
{
strcpy(clas1,buf);
}
*ch = a;
strcpy(buf,ch);
}
ch = &buf[strlen(buf)];
}
fclose(fp);
}