[急]求救高手::help
题目:从一个文件source.txt中读入,经过处理,输出结果为:"#PROGRAM#source#;#.....#:;#....#.#"具体我的编程如下,但就是不行;请高手帮忙指正,谢谢!!
我的程序如下:
#include<iostream>
#include<fstream>
#include<ctype.h>
using namespace std;
int main()
{
char buf[128],ch;
buf[0]='#';
int i=1;
ifstream fin("source.txt",ios::in);
while (1) {
ch=fin.get();
if(ch==' '||ch=='/t'||ch=='/n');
else if(ch=='{'){
ch=fin.get();
while(isalpha(ch)||ch==' '||ch=='/t'||ch=='.')
ch=fin.get();
}
else if(ch=='}');
else if(isalpha(ch)){
buf[i++]='#';
buf[i++]=ch;
ch=fin.get();
while(isalpha(ch))
buf[i++]=ch;
buf[i++]='#';
}
else if(isdigit(ch)){
buf[i++]='#';
buf[i++]=ch;
ch=fin.get();
while(isdigit(ch))
buf[i++]=ch;
buf[i++]='#';
}
else if(ch==';'||ch==','||ch=='-'||ch=='('||ch==')')
buf[i++]=ch;
else if(ch=='+'||ch=='-'||ch=='*'){
buf[i++]=ch;
buf[i++]='#';
}
else if(ch==':'){
buf[i++]=ch;
ch=fin.get();
while(ch=='=')
buf[i++]=ch;
}
else if(ch==EOF){
buf[i]='#';
exit(1);
}
}
for(int j=0;j<=128;i++)
cout<<buf[j];
return 0;
}
其中source.txt里面的内容如下:
PROGRAM source;
{this little source program is used to
illustrate compiling proceduce.}
VAR x,y,z:integer;
a:integer;
BEGIN
{this program has only four executable statements.}
x:=23+5;
z:=x DIV - 3;
y:z+18*3;
a:=x+(y-2) DIV 4;
END.