Hirdetés

Új hozzászólás Aktív témák

  • Dirty_Pio

    csendes tag

    válasz Dirty_Pio #837 üzenetére

    Kozbe reajottem egy-ket hibara szoval az uj kod mar igy nez ki

    #include <stdio.h>
    #include <stdlib.h>
    enum star_type{ MA,BIN,VAR};
    typedef struct {
    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=(stars *)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);
    }

    de meg mindig nem megy :)

Új hozzászólás Aktív témák