level 1
632853406
楼主
程序本来是在d盘找到个input 输出在ouput里,我希望让它在控制台输入,在控制台输出!!
#include"conio.h" //包含getch函数的头文件
#include"stdlib.h" //包含exit函数的头文件
#include <stdio.h>
#include <string.h>
char prog[64],token[8],ch,tmp;
int syn,p,m,n,sum,rows;
char *rwtab[6]={"int","real","if","then","else","while"};
scaner();
main()
{
FILE *out;
FILE *in;
rows=1;
if((out=fopen("d:\\output.txt","wt"))==NULL)
{printf("\non error buiding d:\\output.txt\n");
getch();
exit(1);
}
if((in=fopen("d:\\input.txt","rt"))==NULL)
{printf("\nConn't found d:\\input.txt\n");
getch();
exit(1);
}/* printf("\n please input a string(end with '#'):\n");*/
rewind(in);
rewind(out);
fprintf(out,"%-5s%-10s%-5s%5s\n","type","name","rows","cols");
do{
p=0;
do
{ /*scanf("%c",&ch);*/
if(p==80)
{printf("\non error colun***ength more than 80!\n");
getch();
exit(1);
}
ch=fgetc(in);
prog[p++]=ch;
}while(ch!=EOF&&ch!='\n');
prog[p]='#';
tmp=ch;
p=0;
do{
scaner();
switch(syn)
{case 11:fprintf(out,"%-5d%-10d%-5d%5d\n",syn,sum,rows,p);
break;
case -1:printf("you have input a wrong string,rows cols=(%d,%d)\n",rows,p);
getch();
exit(0);
default:if(syn!=0) fprintf(out,"%-5d%-10s%-5d%5d\n",syn,token,rows,p);
break;
}
}while(syn!=0);
if(tmp=='\n') rows++;
}while(ch!=EOF);
fclose(in);
fclose(out);
}
2012年04月20日 00点04分
1
#include"conio.h" //包含getch函数的头文件
#include"stdlib.h" //包含exit函数的头文件
#include <stdio.h>
#include <string.h>
char prog[64],token[8],ch,tmp;
int syn,p,m,n,sum,rows;
char *rwtab[6]={"int","real","if","then","else","while"};
scaner();
main()
{
FILE *out;
FILE *in;
rows=1;
if((out=fopen("d:\\output.txt","wt"))==NULL)
{printf("\non error buiding d:\\output.txt\n");
getch();
exit(1);
}
if((in=fopen("d:\\input.txt","rt"))==NULL)
{printf("\nConn't found d:\\input.txt\n");
getch();
exit(1);
}/* printf("\n please input a string(end with '#'):\n");*/
rewind(in);
rewind(out);
fprintf(out,"%-5s%-10s%-5s%5s\n","type","name","rows","cols");
do{
p=0;
do
{ /*scanf("%c",&ch);*/
if(p==80)
{printf("\non error colun***ength more than 80!\n");
getch();
exit(1);
}
ch=fgetc(in);
prog[p++]=ch;
}while(ch!=EOF&&ch!='\n');
prog[p]='#';
tmp=ch;
p=0;
do{
scaner();
switch(syn)
{case 11:fprintf(out,"%-5d%-10d%-5d%5d\n",syn,sum,rows,p);
break;
case -1:printf("you have input a wrong string,rows cols=(%d,%d)\n",rows,p);
getch();
exit(0);
default:if(syn!=0) fprintf(out,"%-5d%-10s%-5d%5d\n",syn,token,rows,p);
break;
}
}while(syn!=0);
if(tmp=='\n') rows++;
}while(ch!=EOF);
fclose(in);
fclose(out);
}