| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
- #include <stdlib.h>
 
 - #include <string.h>
 
 - #include<iomanip>
 
 - #include <iostream>
 
 - using namespace std;
 
  
- #define MAXWORD 25
 
 - #define MAXMEAN 50
 
 - #define FILEN 100  //读取文件时一行数据的长度
 
 - struct record   //记录结构_读者
 
 - {
 
 -     char word[MAXWORD + 1];   //key
 
 -     char mean[MAXMEAN + 1];
 
 - };
 
  
- struct lnode    //链表结点结构
 
 - {
 
 -     struct record data;
 
 -     struct lnode* next;
 
 - };
 
  
- int main(int argc, char* argv[])
 
 - {
 
 -     struct lnode* dictionary[26];
 
  
-     /* 头结点 */
 
 -     for (int i = 0; i < 26; i++)
 
 -     {
 
 -         dictionary[i] = (struct lnode*)malloc(sizeof(struct lnode));
 
 -         if (dictionary[i] != NULL)
 
 -         {
 
 -             dictionary[i]->next = NULL; //初始化
 
 -         }
 
 -     }
 
 - }
 
  复制代码 
调试到for循环时报错
报错?不应该吧?报了什么错? 
还有,你这代码是C++ ? 
不要在C++中使用malloc/free
 - #include <stdlib.h>
 
 - #include <string.h>
 
 - #include<iomanip>
 
 - #include <iostream>
 
 - using namespace std;
 
  
- #define MAXWORD 25
 
 - #define MAXMEAN 50
 
 - #define FILEN 100  //读取文件时一行数据的长度
 
 - struct record   //记录结构_读者
 
 - {
 
 -     char word[MAXWORD + 1];   //key
 
 -     char mean[MAXMEAN + 1];
 
 - };
 
  
- struct lnode    //链表结点结构
 
 - {
 
 -     struct record data;
 
 -     struct lnode* next;
 
 - };
 
  
- int main(int argc, char* argv[])
 
 - {
 
 -     struct lnode* dictionary[26];
 
  
-     /* 头结点 */
 
 -     for (int i = 0; i < 26; i++)
 
 -     {
 
 -         dictionary[i] = (struct lnode*)malloc(sizeof(struct lnode));
 
 -         if (dictionary[i] != NULL)
 
 -         {
 
 -             dictionary[i]->next = NULL; //初始化
 
 -         }
 
 -     }
 
  
 
-     for(size_t i = 0; i < 26; ++i) {
 
 -         free(dictionary[i]);
 
 -     }
 
 -     return 0;
 
 - }
 
 
  复制代码 
 
 
 |   
 
 
 
 |