Új hozzászólás Aktív témák
-
Dirty_Pio
csendes tag
Sziasztok, volna egy problemam a kovetkezo feladatban :
#include <stdio.h>
#include <stdlib.h>
enum star_type{ MA,BIN,VAR};
typedef struct s{
char name[51];
enum star_type tp;
union star{
struct mai{
unsigned char type:2;
unsigned char age:2;
char color[11];
}m;
struct bin{
float r1;
float r2;
unsigned char t1:2;
unsigned char t2:2;
}b;
struct var{
float lowlmn;
float highlmn;
float period;
}v;
}u;
}stars;
int main(void){
enum star_type a;
int n,i;
stars *x=malloc(sizeof(stars)*10);
printf("which type of definition would you like to use for the stars?\n");
scanf("%d",&a);
printf("How many stars?(max 10)\n");
scanf("%d",&n);
for (i=0;i<n;i++){
switch (a){
MA:
scanf("%50s",x.name);
x.tp=a;
scanf("%c %c %s",x.u.m.type, x.u.m.age, x.u.m.color);
break;
BIN:
scanf("%50s",x.name);
x.tp=a;
scanf("%f %f %c %c",x.u.b.r1,x.u.b.r2,x.u.b.t1,x.u.b.t2);
break;
VAR:
scanf("%50s",x.name);
x.tp=a;
scanf("%f %f %f",x.u.v.lowlmn,x.u.v.highlmn,x.u.v.period);
break;
default break;
};
for (i=0;i<n;i++)
switch (x.tp){
MA:
printf("%c %c %s\n",x.u.m.type, x.u.m.age, x.u.m.color);
break;
BIN:
printf("%f %f %c %c\n",x.u.b.r1,x.u.b.r2,x.u.b.t1,x.u.b.t2);
break;
VAR:
printff("%f %f %f\n",x.u.v.lowlmn,x.u.v.highlmn,x.u.v.period);
break;
default break;
};
system("pause");
return(0);
}nos, azt az errort adja, hogy name is not a struct or union. Probaltam siman csak egy valtozoba beolvasni az elemeket de ugy meg amikor a unionba akarok olvasni akkor szepen elmegy vegtelenbe, szoval nem igazan tudom mihez kezdjek.
Új hozzászólás Aktív témák
● olvasd el a téma összefoglalót!
● ha kódot szúrsz be, használd a PROGRAMKÓD formázási funkciót!
- Samsung Galaxy S22 Plus / 8/128GB / Kártyafüggetlen / 12Hó Garancia
- GYÖNYÖRŰ iPhone 13 Pro 128GB Graphite -1 ÉV GARANCIA - Kártyafüggetlen, MS3083
- Xiaomi Redmi 12C 64GB, Kártyafüggetlen, 1 Év Garanciával
- BESZÁMÍTÁS! ASRock H410M i3 10100F 16GB DDR4 120GB SSD 1TB HDD GTX 1050 Ti 4GB Zalman ZM-T7 400W
- BESZÁMÍTÁS! Gigabyte B450M R5 5600 16GB DDR4 512GB SSD GTX 1080Ti 11GB ZALMAN I3 NEO Chieftec 650W
Állásajánlatok
Cég: FOTC
Város: Budapest