C初学,求教、哪里导致运行错误?

CodeMaker_12138 2011-11-28 04:38:41
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
typedef struct wordnode{
char Eword[30];
char Chinese[100];
struct wordnode* next;
}WORDNODE;
WORDNODE* Create()
{
int i=-1,len=sizeof(WORDNODE),j,m,n;
char gwords[30][130];
WORDNODE *p1,*p2,*h;
p1=p2=h=(WORDNODE*)malloc(len);
do
{
j=0;
m=0;
i++;

gets(gwords[i]);
if(gwords[i][1]!='#'&&gwords[i][0]!='#')
{
p1=p2;
while(!isspace(gwords[i][j]))
{
p1->Eword[j]=gwords[i][j];
j=j+1;
}
p1->Eword[j]='\0';
for(n=j+1;n<(int)strlen(gwords[i]);n++)
{
p1->Chinese[m]=gwords[i][n];
m=m+1;
}
p1->Chinese[m]='\0';
p2=(WORDNODE*)malloc(len);
p1->next=p2;
}
else
{
p1->next=NULL;
free(p2);
}

}while(gwords[i][1]!='#'&&gwords[i][0]!='#');
return h;
}
void print(WORDNODE* h)
{
WORDNODE*p;
p=h;
while(p!=NULL)
{
printf("%s %s\n",p->Eword,p->Chinese);
p=p->next;
}
}
int main()
{
print(Create());
return 0;
}



...全文
118 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
CodeMaker_12138 2011-11-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ouyh12345 的回复:]

单步跟踪一下,查看变量的值
[/Quote]
谢啦,我用vc6.0的但是不会调试,请问在哪儿能找到学习的资源?
CodeMaker_12138 2011-11-28
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 xxyxxb 的回复:]

while(gwords[i][1]!='#'&&gwords[i][0]!='#'); 这一步意味着你输入的字符串要以“#”结尾,否则,循环次数不可预测,非常有可能导致数组越界。
[/Quote]

多谢,改大点就好了、
小笨同学 2011-11-28
  • 打赏
  • 举报
回复
while(gwords[i][1]!='#'&&gwords[i][0]!='#'); 这一步意味着你输入的字符串要以“#”结尾,否则,循环次数不可预测,非常有可能导致数组越界。
ouyh12345 2011-11-28
  • 打赏
  • 举报
回复
单步跟踪一下,查看变量的值

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧