0
Why showing error
3 Antworten
+ 1
Don't use typedef union, just use : union id in the first line
This :
union id{
int id_num;
char name[20];
}id;
+ 1
Typedef doesn't work the way you think it does, eg.
Typedef struct {
// Some data
} ID;
now ID will be the structure, and then it will work like this :
ID Ob;
// An object of the structure
Eg.2
typedef double Dec;
Now you can use Dec as a keyword in place of double
Now I will modify your code according to that, and it becomes :
#include <stdio.h>
#include <string.h>
typedef union{
int id_num;
char name[20];
}id;
void set_id (id *item);
void show_id (id item);
int main() {
id item;
set_id(&item);
show_id(item);
return 0;
}
void set_id(id *item) {
item->id_num = 42;
}
void show_id(id item) {
printf("ID is %d", item.id_num);
}
0
Why