I am unable to assign one structure variable (R2 = R1
) to another structure variable. Please help me to understand, why the following program is not getting compiled and what is the best way to assign one structure variable to other?
I'm tired with the pointers way. Still code is not getting compiled...
Code1:
#include<stdio.h>
struct Record
{
int ID;
char Name[];
} R1 = {1234, "King"}, R2;
R2 = R1;
int main()
{
printf("%d %s \n", R1.ID, R1.Name);
printf("%d %s \n", R2.ID, R2.Name);
}
Code2:
#include<stdio.h>
struct Record
{
int ID;
char Name[];
} R1 = {1234, "King"}, *R2;
R2 = &R1;
int main()
{
printf("%d %s \n", R1.ID, R1.Name);
printf("%d %s \n", R2->ID, R2->Name);
}