一个c的问题

来源:百度知道 编辑:UC知道 时间:2024/05/17 15:22:49
#include <math.h>
#include <stdlib.h>
struct node
{double a,b,c;
struct node *next;
};
struct node *ha(struct node *d)
{scanf("%lf,%lf,%lf",&d->a,&d->b,&d->c);
return d;
}
main()
{double e;
struct node *d;
ha(d);
e=(d->a)+(d->b)+(b->c);
printf("%lf",e);
free(d);
}
这个程序不行,如果换成int就可以
#include <math.h>
#include <stdlib.h>
struct node
{int a,b,c;
struct node *next;
};
struct node *ha(struct node *d)
{scanf("%d,%d,%d",&d->a,&d->b,&d->c);
return d;
}
main()
{int e;
struct node *d;
ha(d);
e=(d->a)+(d->b)+(b->c);
printf("%d",e);
free(d);
} 哪里出错了?谢谢

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
struct node
{double a,b,c;
struct node *next;
};
struct node *ha(struct node *d)
{scanf("%lf,%lf,%lf",&d->a,&d->b,&d->c);
return d;
}
void main()
{double e;
struct node *d=(node *)malloc(sizeof(node));
ha(d);
e=(d->a)+(d->b)+(d->c);
printf("%lf",e);
free(d);
}

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
struct node
{int a,b,c;
struct node *next;
};
struct node *ha(struct node *d)
{scanf("%d,%d,%d",&d->a,&d->b,&d->c);
return d;
}
void main()
{int e;
struct node *d=(node *)malloc(sizeof(node));
ha(d);
e=(d->a)+(d->b)+(d->c);
printf("%d",e);
free(d);
}