筒单的C语言问题

来源:百度知道 编辑:UC知道 时间:2024/06/02 15:28:56
这三行被注释的代码错了,搞了半天看不出错啊!
// a=s->name;
// s->name=s->next->name;
// s->next->name=a;
}

#include <stdio.h>
#include <malloc.h> /*包含动态内存分配函数的头文件*/
#define N 10 /*N为人数*/
typedef struct node//定义链表的节点结构
{
char name[20];
struct node *Back;
struct node *next;
}stud;

typedef struct link//定义完整链表的常用信息
{
struct node *head;//表头
struct node *foot;//表尾节点
int length;//长度包括表头节点
}stud2;

struct link * creat() /*建立链表的函数*/
{
stud2 *qq;
stud *p,*h,*s; /* *h保存表头结点的指针,*p指向当前结点的前一个结点,*s指向当前结点*/
if((qq=(stud *)malloc(sizeof(stud2)))==NULL) /*分配空间并检测*/
{
printf("不能分配内存空间!");
exit(0);
}
if((h=(stud *)malloc(sizeof(stud)))==NULL) /*分配空间并检测*/
{
printf("不能分配内存空间!");
exit(0);
}
h->name[0]='\0'; /*把表头结点的

那是指针问题,指针很重要哦!!

char a[20]; // a=s->name;
a是数组,name也是数组,这样对数组的地址赋值是不允许的(常量)。可以考虑使用strcpy来赋值