【发布时间】:2017-09-12 04:18:45
【问题描述】:
好吧我不需要解释太多,这个函数在我一直标记的那一行得到这个错误,只有在这个函数中有内存分配,请帮我找出问题所在......(阅读这里有一些其他主题,但没有任何帮助我解决它) 错误:“Windows 已在 sapProject.exe 中触发断点。
这可能是由于堆损坏,这表明 sapProject.exe 或其已加载的任何 DLL 中存在错误。 "
void storeTok(char * lexem,int line,enum keywords typeof)
{
int ind;
if(tokens.size%100==0)
{
if(tokens.size==0)
{
tokens.ptrInd=-1;
tokens.first=(node*)malloc(sizeof(node));
tokens.first->back = NULL;
tokens.first->next = NULL;
tokens.last=tokens.first;
}
else
{
node * nodenz=(node*)malloc(sizeof(node)); /error is here
nodenz->back = tokens.last;
nodenz->next = NULL;
tokens.last->next=nodenz;
tokens.last=tokens.last->next;
tokens.last=nodenz;
}
}
// general
ind=tokens.size-(tokens.size/100)*100;
tokens.last->tokens[ind].type=typeof;
tokens.last->tokens[ind].linen=line;
tokens.last->tokens[ind].lexema=lexem;
tokens.size++;
}
谢谢!
编辑(除了这个,还有一个标题(就是这样..):
typedef struct token
{
char * lexema ;
int linen;
enum keywords type;
}token;
typedef struct node
{
struct node * next,*back;
token tokens [50];
}node;
typedef struct LL
{
struct node * last, *first, * ptr;
int size,ptrInd;
}LL;
LL tokens;
void storeTok(char * lexem,int line,enum keywords typeof);
主要功能:
void main()
{
int i;
for(i=0;i<26;++i)
{
storeTok("blabla",1,END);
storeTok("sdfasd",1,START);
storeTok("sfadds",1,IF);
storeTok("gvdfd",1,THEN);
storeTok("dfsfd",1,ELSE);
}
storeTok("dfsfd",1,EOF_);
}
【问题讨论】:
-
那我也不解释我的反对意见了。
-
@GhostCat 请解释一下 :) 是不是因为你不喜欢别人提问?
-
只需阅读随附的消息:您的问题已暂停。
-
大声笑,如果有人真的需要一个理由,你的缩进让你很难阅读/遵循你的代码。
标签: c debugging heap-memory