五万行 2013-10-31 07:11 采纳率: 0%
浏览 2351

c++编译通过,运行时弹出窗口说“该内存不能为written”代码如下

//对一串字符串进行分类。
#include
#include
using namespace std;
#define N 256

void getsym(char STR[N],string SYM,string *ID,int *NUM){
char *s;
for(int i=0;i<N;i++) //去空格
{
if(STR[i]!=' ')
{
*s=STR[i];
s++;
}
}
for(i=0;*s!=NULL;i++) //保留字,符号,数字,标识符的识别
{
//识别保留字:var、、const、、begin、end、、while、、do、、read、、write、if、、then、、procedure、、call、、
if((*s=='v')&&(
(s+1)=='a')&&(*(s+2)=='r'))
{
SYM++="var";
cout<<"VARSYM:var"<<endl;
s=s-3;
}
else if((*s=='c')&&(
(s+1)=='o')&&(*(s+2)=='n')&&(*(s+3)=='s')&&(*(s+4)='t'))
{
*SYM++="const";
cout<<"CONSTSYM:const"<<endl;
s=s-5;
}

    else if((*s=='b')&&(*(s+1)=='e')&&(*(s+2)=='g')&&(*(s+3)=='i')&&(*(s+4)='n'))
    {
        *SYM++="begin";
        cout<<"BEGINSYM:begin"<<endl;
        s=s-5;
    }


    else if((*s=='e')&&(*(s+1)=='n')&&(*(s+2)=='d'))
    {
        *SYM++="end";
        cout<<"ENDSYM:end"<<endl;
        s=s-3;
    }

    else if((*s=='w')&&(*(s+1)=='h')&&(*(s+2)=='i')&&(*(s+3)=='l')&&(*(s+4)='e'))
    {
        *SYM++="while";
        cout<<"WHILESYM:while"<<endl;
        s=s-5;


    }
    else if((*s=='d')&&(*(s+1)=='o'))
    {
        *SYM++="do";
        cout<<"DOSYM:do"<<endl;
        s=s-2;
    }


    else if((*s=='r')&&(*(s+1)=='e')&&(*(s+2)=='a')&&(*(s+3)=='d'))
    {
        *SYM++="read";
        cout<<"READSYM:read"<<endl;
        s=s-5;
    }

    else if((*s=='w')&&(*(s+1)=='r')&&(*(s+2)=='i')&&(*(s+3)=='t')&&(*(s+4)='e'))
    {
        *SYM++="write";
        cout<<"WRITESYM:write"<<endl;
        s=s-5;
    }

    else if((*s=='i')&&(*(s+1)=='f'))
    {
        *SYM++="if";
        cout<<"IFSYM:if"<<endl;
        s=s-2;
    }
    else if((*s=='t')&&(*(s+1)=='h')&&(*(s+2)=='e')&&(*(s+3)=='n'))
    {
        *SYM++="then";
        cout<<"THENSYM:then"<<endl;
        s=s-4;
    }
    else if((*s=='p')&&(*(s+1)=='r')&&(*(s+2)=='o')&&(*(s+3)=='c')&&(*(s+4)='e')&&(*(s+5)='d')&&(*(s+6)='u')&&(*(s+7)='r')&&(*(s+8)='e'))
    {
        *SYM++="procedure";
        cout<<"PROCEDURESYM:procedure"<<endl;
        s=s-9;
    }
    else if((*s=='c')&&(*(s+1)=='a')&&(*(s+2)=='l')&&(*(s+3)='l'))
    {
        *SYM++="call";
        cout<<"CALLSYM:call"<<endl;
        s=s-4;
    }
    //识别符号
    else if((*s==',')||(*s==';')||(*s==':')||(*s=='=')||(*s=='>')||(*s=='<')||(*s=='!')||(*s=='(')||(*s==')')||(*s=='.'))
    {
        cout<<"symbol:"<<*s<<endl;
        s=s-1;
    }
    //识别数字
    else if((*s<58)&&(*s>48))
    {
        *NUM++=*s;
        cout<<"number:"<<*s<<endl;
        s=s-1;
    }
    //识别标识符
    else
    {
        cout<<*s;
        s=s-1;
    }
}

}

int main()
{
char str[N];
string *sym=0,*id=0;
int *num=0;
cout<<"please input the code:\n";
for(int i=0;i {
cin>>str[i];
if(str[i]=='.')
break;
}
getsym(str,sym,id,num);
return 0;
}

  • 写回答

1条回答

  • Eleven 2015-01-04 11:33
    关注

    请先在Debug模式下打开call stack,看看函数调用堆栈,先找到出错的函数调用。

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。