我有个问题想请高手解答一下!是C语言的!谢谢了!我有急用
2005-04-29 21:09
731 查看
我做的是编译原理的程序
为什么我的这个程序运行七次后(我设了个while 循环)还能运行可就是有错误
还在DOS下有提示:Nnll pointer assignment
请看下啊:#include
#include
FILE *f,*s,*id,*nu;
int cc=0;
char *bao[15]={"+","-","*","/",";","=","+=","-=","*=","/=",
"IDENT","NUMBER","if","then","else"};
char getcha(FILE*f)
{static ch[81];
char cha;
int i=0;
if(cc==0)
{
cha=fgetc(f);
while ( cha!=-1 && (i<80) )
{ch[i++]=cha;
cha=fgetc(f);}
if(cha==-1) ch[i]='.';
i=0;
}
cha=ch[cc++];
if(cc==79 || cha=='.')
cc=0;
if (cha==-1)
{ printf("/nfile is null!/n");
return cha=0;
}
else return cha;
}
void shuru()
{char ch1[100],ch,*p;
int i;
printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
f=fopen("chengxu","w");
while(1)
{ p=ch1;
gets(ch1);
while (ch=*(p++))
fputc(ch,f);
if(*(p-2)=='.')
break;
}
fclose(f);
}
fputi(int i,FILE *s)
{ int n=0,ch[5],m;
while(i>=10)
{ ch[n++]=i%10;
i/=10;
}
ch
=i;
for(i=n;i>=0;i--)
fputc(ch[i]+'0',s);
fputc('#',s);
}
main()
{ char ch1,ch2,cha3,ch[11],*d;
int i,n=0,m=0;
do{ cc=0;
shuru();
f=fopen("chengxu","r");
s=fopen("sym","w");
id=fopen("ident","w");
nu=fopen("number","w");
ch1=getcha(f);
while(1)
if(ch1!='.')
{ if(ch1!=' ')
{ if(((ch1>=65) && (ch1<=90))||((ch1>=97) && (ch1<=122)))
{ i=0;
d=ch;
do{if(i<=9)
ch[i++]=ch1;
ch1=getcha(f);
} while (((ch1>=65)&&(ch1<=90))||((ch1>=97)&&(ch1<=122))||((ch1>='0')&&(ch1<='9'))) ;
ch[i]='/0';
for(i=12;(i<15)&&strcmp(d,bao[i]);i++);
if(strcmp(d,bao[i])==0)
fputi(i,s);
else {fputi(10,s);
i=0;
while(ch2=ch[i++])
fputc(ch2,id);
fputc('#',id);
}
}
else if((ch1>='0')&&(ch1<='9'))
{
do{ fputc(ch1,nu);
ch1=getcha(f);
} while((ch1>='0')&&(ch1<='9'));
fputc('#',nu);
fputi(11,s);
}
else if(ch1!=' ')
{ i=0;
do
{switch(ch1)
{ case '+':n=0;break;
case '-':n=1;break;
case '*':n=2;break;
case '/':n=3;break;
case ';':n=4;break;
case '=':n=5;break;
default :n=100;
}
if((ch1<65||ch1>90)&&(ch1<97 || ch1>122)&&(ch1<'0' || ch1>'9'))
{
ch[i++]=ch1;
ch1=getcha(f);
}
}while (n!=100);
ch[i]='/0';
if(i!=0 )
{ for(i=0;i<10 && strcmp(ch,bao[i]);i++);
if (strcmp(ch,bao[i])==0)
fputi(i,s);
else {
printf("/n%s :it is wrong!",ch);
break;
}
}
}
}
else ch1=getcha(f);
}
else break;
fclose(f);
fclose(s);
fclose(id);
fclose(nu);
fopen("chengxu","r");
f=fopen("sym","r");
fopen("ident","r");
fopen("number","r");
while((ch1=fgetc(f))!=-1)
putchar(ch1);
putchar('/n');
fclose(f);
printf("ones again?(y/n)");
cha3=getchar();
m++;
}while (cha3=='y' ||cha3=='Y');
printf("/n%d/n",m);
}
为什么我的这个程序运行七次后(我设了个while 循环)还能运行可就是有错误
还在DOS下有提示:Nnll pointer assignment
请看下啊:#include
#include
FILE *f,*s,*id,*nu;
int cc=0;
char *bao[15]={"+","-","*","/",";","=","+=","-=","*=","/=",
"IDENT","NUMBER","if","then","else"};
char getcha(FILE*f)
{static ch[81];
char cha;
int i=0;
if(cc==0)
{
cha=fgetc(f);
while ( cha!=-1 && (i<80) )
{ch[i++]=cha;
cha=fgetc(f);}
if(cha==-1) ch[i]='.';
i=0;
}
cha=ch[cc++];
if(cc==79 || cha=='.')
cc=0;
if (cha==-1)
{ printf("/nfile is null!/n");
return cha=0;
}
else return cha;
}
void shuru()
{char ch1[100],ch,*p;
int i;
printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
f=fopen("chengxu","w");
while(1)
{ p=ch1;
gets(ch1);
while (ch=*(p++))
fputc(ch,f);
if(*(p-2)=='.')
break;
}
fclose(f);
}
fputi(int i,FILE *s)
{ int n=0,ch[5],m;
while(i>=10)
{ ch[n++]=i%10;
i/=10;
}
ch
=i;
for(i=n;i>=0;i--)
fputc(ch[i]+'0',s);
fputc('#',s);
}
main()
{ char ch1,ch2,cha3,ch[11],*d;
int i,n=0,m=0;
do{ cc=0;
shuru();
f=fopen("chengxu","r");
s=fopen("sym","w");
id=fopen("ident","w");
nu=fopen("number","w");
ch1=getcha(f);
while(1)
if(ch1!='.')
{ if(ch1!=' ')
{ if(((ch1>=65) && (ch1<=90))||((ch1>=97) && (ch1<=122)))
{ i=0;
d=ch;
do{if(i<=9)
ch[i++]=ch1;
ch1=getcha(f);
} while (((ch1>=65)&&(ch1<=90))||((ch1>=97)&&(ch1<=122))||((ch1>='0')&&(ch1<='9'))) ;
ch[i]='/0';
for(i=12;(i<15)&&strcmp(d,bao[i]);i++);
if(strcmp(d,bao[i])==0)
fputi(i,s);
else {fputi(10,s);
i=0;
while(ch2=ch[i++])
fputc(ch2,id);
fputc('#',id);
}
}
else if((ch1>='0')&&(ch1<='9'))
{
do{ fputc(ch1,nu);
ch1=getcha(f);
} while((ch1>='0')&&(ch1<='9'));
fputc('#',nu);
fputi(11,s);
}
else if(ch1!=' ')
{ i=0;
do
{switch(ch1)
{ case '+':n=0;break;
case '-':n=1;break;
case '*':n=2;break;
case '/':n=3;break;
case ';':n=4;break;
case '=':n=5;break;
default :n=100;
}
if((ch1<65||ch1>90)&&(ch1<97 || ch1>122)&&(ch1<'0' || ch1>'9'))
{
ch[i++]=ch1;
ch1=getcha(f);
}
}while (n!=100);
ch[i]='/0';
if(i!=0 )
{ for(i=0;i<10 && strcmp(ch,bao[i]);i++);
if (strcmp(ch,bao[i])==0)
fputi(i,s);
else {
printf("/n%s :it is wrong!",ch);
break;
}
}
}
}
else ch1=getcha(f);
}
else break;
fclose(f);
fclose(s);
fclose(id);
fclose(nu);
fopen("chengxu","r");
f=fopen("sym","r");
fopen("ident","r");
fopen("number","r");
while((ch1=fgetc(f))!=-1)
putchar(ch1);
putchar('/n');
fclose(f);
printf("ones again?(y/n)");
cha3=getchar();
m++;
}while (cha3=='y' ||cha3=='Y');
printf("/n%d/n",m);
}
相关文章推荐
- 求信息高手参考一下~我说的问题??谢谢
- 主题:大家好!哪位高手帮我解答一个c#.net方面的问题,谢谢
- 向高手请教一下使用jacob打印word时出现的异常,有谁能够解答,谢谢!小女子感激不尽啊!
- 今天写链表时候遇到的问题,请高手解答一下
- 数据结构 栈问题(在TC能运行,但是是死循环,请高手帮忙调试一下,谢谢~)
- 最近遇到一个问题,哪位高手能帮忙解答一下
- 帮我解答谢谢 几个c语言问题
- 编引用之swap()---高手帮忙写下笔记,还有解决一下问题,谢谢了
- 求大神帮解答javaEE这个问题,谢谢了
- [VB.NET]关于程序性能问题,高手请进,谢谢
- SQL高手请进来一下,谢谢
- 蓝牙问题。请真正的c#高手帮忙?谢谢
- 我是个vb初学者想请教高手点简单的vb问题如果可以请加我的QQ:382245409谢谢
- 有哪位高手帮忙解决一下问题!!!DataContract 的using引用指令用什么?
- 建立系统公用类时遇到一个问题!请哪位高手帮忙指点一下!谢了!!!
- 求高手用java代码帮我做一下这道题,谢谢。如果可以的话,请讲一下格式化输出。
- 选太子 C语言问题解答
- C二级问题跪求高手解答!!
- 请高手指点,PHP问题,解密出一个文件,不知道这个是什么用的,怎么使用,谢谢好友指点
- 谢谢了 大家好.能帮我做一下C语言这些题吗