链表中字符串的导入
发布网友
发布时间:2022-04-24 00:24
我来回答
共1个回答
热心网友
时间:2023-10-15 08:59
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
struct node
{
char valuename[21];
int type;
int ivalue;
double dvalue;
struct node *link;
};
struct node * creat(struct node *p, struct node *h, struct node *s,int t, char *pname,size_t a)//a是name的长度,pname是name的指针
{
if ((s = (struct node *)malloc(sizeof(struct node))) == NULL) /*分配空间并检测*/
{
printf("不能分配内存空间!");
exit(0);
}
p->link = s; /*把s的地址赋给p所指向的结点的链域,这样就把p和s所指向的结点连接起来了*/
memcpy(s->valuename, pname, a);
s->type = t;
s->ivalue = 0;
s->dvalue = 0.0;
printf("%d%s\n", t,s->valuename);
s->link = NULL;
p = s;
return h;
}
//给你改了,好多错误
热心网友
时间:2023-10-15 08:59
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
struct node
{
char valuename[21];
int type;
int ivalue;
double dvalue;
struct node *link;
};
struct node * creat(struct node *p, struct node *h, struct node *s,int t, char *pname,size_t a)//a是name的长度,pname是name的指针
{
if ((s = (struct node *)malloc(sizeof(struct node))) == NULL) /*分配空间并检测*/
{
printf("不能分配内存空间!");
exit(0);
}
p->link = s; /*把s的地址赋给p所指向的结点的链域,这样就把p和s所指向的结点连接起来了*/
memcpy(s->valuename, pname, a);
s->type = t;
s->ivalue = 0;
s->dvalue = 0.0;
printf("%d%s\n", t,s->valuename);
s->link = NULL;
p = s;
return h;
}
//给你改了,好多错误