关于C语言结构体指针的问题,求大神回答....
#include<stdio.h>#include<stdlib.h>typedefstructgoods_node{charnumber[10];floatprice;...
#include<stdio.h>
#include<stdlib.h>
typedef struct goods_node{
char number[10];
float price;
int sum;
struct goods_node *next;
} goods;
typedef struct customer_node{
char name[20];
char address[20];
char Tel[20];
struct customer_node *next;
} customer;
typedef struct order_node{
char orderNumber[10];
goods *a;
customer *c;
int amount;
float pay;
char status[20];
struct order_node *next;
} order;
void main()
{
order *c1;
goods *c2;
customer *c3;
c1=(order*)malloc(sizeof(order));
c2=(goods*)malloc(sizeof(goods));
c3=(customer*)malloc(sizeof(customer));
printf("please inlput:\n");
scanf("%s%f%s",c1->a->number,&c1->a->price,c1->c->Tel);
printf("%5s%6.1f%5s",c1->a->number,c1->a->price,c1->c->Tel);
}
想通过order这个结构体指向里面的goods和customer这两个结构体的变量,但是输不出来,请大神解答.....谢谢 展开
#include<stdlib.h>
typedef struct goods_node{
char number[10];
float price;
int sum;
struct goods_node *next;
} goods;
typedef struct customer_node{
char name[20];
char address[20];
char Tel[20];
struct customer_node *next;
} customer;
typedef struct order_node{
char orderNumber[10];
goods *a;
customer *c;
int amount;
float pay;
char status[20];
struct order_node *next;
} order;
void main()
{
order *c1;
goods *c2;
customer *c3;
c1=(order*)malloc(sizeof(order));
c2=(goods*)malloc(sizeof(goods));
c3=(customer*)malloc(sizeof(customer));
printf("please inlput:\n");
scanf("%s%f%s",c1->a->number,&c1->a->price,c1->c->Tel);
printf("%5s%6.1f%5s",c1->a->number,c1->a->price,c1->c->Tel);
}
想通过order这个结构体指向里面的goods和customer这两个结构体的变量,但是输不出来,请大神解答.....谢谢 展开
2个回答
展开全部
在
c1=(order*)malloc(sizeof(order));
c2=(goods*)malloc(sizeof(goods));
c3=(customer*)malloc(sizeof(customer));
下面添加
c1->a=(goods*)malloc(sizeof(goods));
c1->c=(customer*)malloc(sizeof(customer));
因为你虽然为c1,c2,c3分配了空间,但是没有为c1中的good *a和customer *c分配空间
追问
谢谢你的回答,么么哒.....
展开全部
void main()
{
order *c1;
goods *c2;
customer *c3;
c1=(order*)malloc(sizeof(order));
c2=(goods*)malloc(sizeof(goods));
c3=(customer*)malloc(sizeof(customer));
c1->a=c2;//结构体的成员指针没有初始化赋值,指向不明
c1->c=c3;
printf("please inlput:\n");
scanf("%s%f%s",c1->a->number,&(c1->a->price),c1->c->Tel);
printf("%5s %6.1f %5s",c1->a->number,c1->a->price,c1->c->Tel);
}
{
order *c1;
goods *c2;
customer *c3;
c1=(order*)malloc(sizeof(order));
c2=(goods*)malloc(sizeof(goods));
c3=(customer*)malloc(sizeof(customer));
c1->a=c2;//结构体的成员指针没有初始化赋值,指向不明
c1->c=c3;
printf("please inlput:\n");
scanf("%s%f%s",c1->a->number,&(c1->a->price),c1->c->Tel);
printf("%5s %6.1f %5s",c1->a->number,c1->a->price,c1->c->Tel);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询