user-0 提问: VSCODE运行问题：第一次运行可以运行，第二次报错。

回复:
user: user-0
content: 这个是蔬菜种类信息.csv的基本内容  这个是蔬菜基本信息.csv中的基本内容

user: user-0
content: #include <malloc.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define LEN1 sizeof(struct veg1) //令LEN代表struct  student类型数据的长度  typedef struct information1 //蔬菜基本信息 { 	int num1;			 //排序编号 	int num2;			 //分类码 	char nutrition[100]; //营养成分 	char name[20];		 //蔬菜名字 } information1;  typedef struct information2 //蔬菜种植信息 { 	int num;	   //分类编号 	int area;	   //蔬菜种植面积 	int weight;	   //蔬菜收获重量 	int year;	   //收获年份 	char name[20]; //蔬菜名字 } information2;  typedef struct veg1 //下属大类kind的蔬菜类型 { 	int flag;				  //用于标记该单元是否已经进行访问 	struct information1 info; //结构体蔬菜的数据域 	struct veg1 *next; } veg1;  typedef struct veg2 //用于蔬菜种植信息表的结构体 { 	struct information2 plant_info; //结构体蔬菜的数据域 	struct veg2 *next; } veg2;  typedef struct kind { 	int num; 	char kind_name[20]; //类型名称 	struct kind *right; //并列大类 	struct veg1 *down;	//下属子类 } kind;  kind *creat_trunk();			 //创造大类主链 veg1 *sorting_line(FILE *);		 //添加一个排序主链，用于对蔬菜基本信息表中的蔬菜进行排序和导入大类主链 void insert_veg(kind *, FILE *); //往主链添加蔬菜 void save(veg1 *, FILE *); char *split(char *, char *);  //主链的添加 kind *creat_trunk() { 	int i; 	struct kind *head; 	struct kind *p1, *p2; 	head = (struct kind *)malloc(sizeof(kind)); //表头空节点，可以不赋值，或者赋值一个用不到的值 	p2 = head; 	for (i = 1; i < 6; i++) 	{ 		p1 = (struct kind *)malloc(sizeof(kind)); 		p1->num = i; 		p1->right = NULL; 		p1->down = NULL; 		if (i == 1) 			strcpy(p1->kind_name, "根茎类"); 		else if (i == 2) 			strcpy(p1->kind_name, "果菜类"); 		else if (i == 3) 			strcpy(p1->kind_name, "瓜类"); 		else if (i == 4) 			strcpy(p1->kind_name, "叶菜类"); 		else if (i == 5) 			strcpy(p1->kind_name, "菌类"); 		p2->right = p1; 		p2 = p1; 	} 	p2->right = NULL; 	return (head); //返回头指针 }  //植物的插入 void insert_veg(kind *head, FILE *fp) //creat函数 ：返回值是一个指向student结构体的指针 { 	kind *p; 	int i; 	char buffer[40]; 	char *token, *str; //str是从buffer中取出的整行数据，token用来暂存信息; 	char delim[2] = ","; 	veg1 *p1, *p2[6]; //p1用于创造新结点，p2用于记录每个大类遍历到的当前节点; 	p = head->right; 	for (i = 1; i < 6; i++) 	{ 		p2[i] = (struct veg1 *)malloc(LEN1); //每一列都有一个表头空节点; 		p2[i]->next = NULL; 		p->down = p2[i]; 		p = p->right; 	} 	fseek(fp, 69L, SEEK_CUR); //从表格的第二行开始进行读入 	while ((str = fgets(buffer, sizeof(buffer), fp)) != NULL) 	{ 		p = head->right; 		token = split(str, delim); //第一格不取 		for (i = 1; i < 6; i++) 		{ 			token = split(NULL, delim); 			if (token[0] != '\0') 			{ 				p1 = (struct veg1 *)malloc(LEN1); 				strcpy(p1->info.name, token); 				p1->flag = 0; 				p1->next = NULL; 				p2[i]->next = p1; 				p2[i] = p1; 			} 		} 		p = p->right; 	} }  //字符串分割函数类似于strtok，注意若有n个分割符即n+1个数据，此函数将可以有n+2个输出，最后一个输出为NULL char *split(char *strToken, char *strDelimit) { 	char *p; 	char *pd; 	static char *ps; 	if (strToken != NULL) 	{ 		ps = strToken; 		while ((*ps != '\0') && (*ps != '\n')) 		{ 			ps++; 		} 		*ps = 'X'; //X为标识符，帮助循环结束 		ps++; 		*ps = '\0'; 		ps = strToken; 	} 	p = ps; 	while (*ps != '\0') 	{ 		pd = strDelimit; 		while ((*pd != '\0') && (*pd != *ps)) 			pd++; 		if (*pd == *ps) 		{ 			*ps = '\0'; 			ps++; 			return p; 		} 		else 			ps++; 	} 	if (*(ps - 1) == 'X') 	{ 		*(ps - 1) = '\0'; 		return p; 	} 	return NULL; }  //添加一个排序主链，用于对蔬菜基本信息表中的蔬菜进行排序和导入大类主链 veg1 *sorting_line(FILE *fp) { 	veg1 *head, *cur, *p; 	char buffer[500]; 	char *token, *str; //str是从buffer中取出的整行数据，token用来暂存信息; 	char delim[2] = ","; 	head = (struct veg1 *)malloc(LEN1); //表头空节点; 	cur = head; 	fseek(fp, 35L, SEEK_CUR); //从表格的第二行开始进行读入 	while ((str = fgets(buffer, sizeof(buffer), fp)) != NULL) 	{ 		p = (struct veg1 *)malloc(LEN1); 		token = split(str, delim); //导入总排序号 		p->info.num1 = atoi(token); 		printf("%d ", p->info.num1); 		token = split(NULL, delim); //导入蔬菜名称 		strcpy(p->info.name, token); 		printf("%s ", p->info.name); 		token = split(NULL, delim); //导入蔬菜分类码 		p->info.num2 = atoi(token); //字符串转整型函数atoi 		printf("%d\n", p->info.num2); 		token = split(NULL, delim); //导入营养成分 		strcpy(p->info.nutrition, token); 		cur->next = p; 		cur = p; 		p->next = NULL; 	} 	return head; }  int main() { 	int i; 	kind *head1, *p1; //head1为主链类型头指针,p1用于操作主链 	veg1 *L_head1[5]; //L_head1为主链下属分链头指针 	veg1 *pp[5];	  //pp用于操作主链下属分链 	veg1 *sort_head;  //排序链表表头指针 	veg1 *tp;		  //tp为测试指针 	FILE *fp;  	//创建主链 	head1 = creat_trunk(); 	fp = fopen("C:\\Users\\40375\\Desktop\\课程设计\\任务一数据\\csv\\蔬菜种类信息表.csv", "r+"); 	if (fp == NULL) 	{ 		printf("fail to open the file!!!\n"); 		fclose(fp); 		return 0; 	} 	insert_veg(head1, fp); 	p1 = head1->right->right->right->right->right; 	L_head1[0] = p1->down->next; 	while (L_head1[0] != NULL) 	{ 		printf("%s\n", L_head1[0]->info.name); 		L_head1[0] = L_head1[0]->next; 	} 	fclose(fp);  	//初始化五个表头指针 	p1 = head1->right; 	for (i = 0; i < 5; i++) 	{ 		L_head1[i] = p1->down; 		pp[i] = L_head1[i]->next; 		p1 = p1->right; 	} 	//创造排序链 	fp = fopen("C:\\Users\\40375\\Desktop\\蔬菜基本信息表.csv", "r"); 	if (fp == NULL) 	{ 		printf("fail to open the file!!!\n"); 		fclose(fp); 		return 0; 	} 	printf("文件打开成功\n"); 	sort_head = sorting_line(fp); 	tp = sort_head->next; 	fclose(fp); 	return 0; }

user: user-1
content: 数组越界了，下标为-1了

user: user-2
content: 你的代码呢？贴图内容如何能定位问题？