-
struct question
Code:
#include<stdio.h>
struct game
{
int level;
int score;
struct player
{
char *name;
}g2={"anil"};
}g3={10,200};
void main()
{
struct game g1=g3;
clrscr();
printf("%d %d %s",g1.level,g1.score,g1.g2.name);
getch();
}
output:
Line 9: error: expected ':', ',', ';', '}' or '__attribute__' before '=' token
In function 'main':
Line 15: error: 'struct game' has no member named 'g2'
What is the reason behind the error messages?
-
The resason for the error messages is that you are typing in garbage code...
-
The initialiser for your struct would be
Code:
struct game
{
int level;
int score;
struct player
{
char *name;
}g2;
}g3 = { 100, 200, { "hello" } };
-
Thanks Salem...That helped