I'm working with structures in c
, but I can not give value to the structures' attributes.
#include <stdio.h>
#include <string.h>
struct Book{
char name[10];
int id;
};
int main(){
char tmp_name[10];
int tmp_id;
for(;;){
struct Book a;
scanf("%s",tmp_name);
scanf("%d", tmp_id);
strcpy(a.name,tmp_name);
a.id = tmp_id;
printf("name: %s\nid:%d", a.name, a.id);
}
return 0;
}
This code compiles correctly but occurs Segmentation fault (core dumped)
error.