#include
#include
#include
struct Node;
typedef struct Node *PNode;
struct Node
{
char le[30], tran[130];
PNode link;
};
typedef struct Node *LinkString;
LinkString createNullDictionary(void)
{
LinkString pdic;
pdic = (LinkString)malloc(sizeof(struct Node));
if (pdic != NULL)
pdic->link = NULL;
else printf("空間不足!\n");
return (pdic);
}
int main(void)
{
FILE *fp;
PNode pre;
int i, j;
PNode p;
p = (PNode)malloc(sizeof(struct Node));
i = j = 0;
char str[100];
pre = createNullDictionary();
errno_t eer;
eer = fopen_s(&fp, "詞典數據.txt", "r");
if (fp == NULL)
{
printf("空!\n");
return(0);
}
else
{
while (fgets(str, 100, fp)!=NULL)
{
while (str[i] != ' ')
{
p->le[i] = str[i];//就是這一行。。。萬惡的這一行,第二次循環的時候中斷
i++;
}
p->le[i] = '\0';
i++;
while (str[i] != '\n')
{
p->tran[j] = str[i];
i++;
j++;
}
p->tran[j] = '\0';
printf("%s %s\n",p->le,p->tran);
p = pre->link;
pre = p;
}
}
}
代碼如上 謝謝各位了!
問題出在i和j上。第二次循環單步看下i和j的值,你就明白了。