C++报错 读取字符串字符时出错
#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; //key
char mean;
};
struct lnode //链表结点结构
{
struct record data;
struct lnode* next;
};
int main(int argc, char* argv[])
{
struct lnode* dictionary;
/* 头结点 */
for (int i = 0; i < 26; i++)
{
dictionary = (struct lnode*)malloc(sizeof(struct lnode));
if (dictionary != NULL)
{
dictionary->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; //key
char mean;
};
struct lnode //链表结点结构
{
struct record data;
struct lnode* next;
};
int main(int argc, char* argv[])
{
struct lnode* dictionary;
/* 头结点 */
for (int i = 0; i < 26; i++)
{
dictionary = (struct lnode*)malloc(sizeof(struct lnode));
if (dictionary != NULL)
{
dictionary->next = NULL; //初始化
}
}
for(size_t i = 0; i < 26; ++i) {
free(dictionary);
}
return 0;
}
页:
[1]