This is my C program...
#include <stdio.h>
struct xyx {
int x;
int y;
char c;
char str[20];
int arr[2];
};
int main(void)
{
struct xyz a;
a.x = 100;
printf("%d\n", a.x);
return 0;
}
This is the error that I am getting....
Press ENTER or type command to continue
13structtest.c: In function ‘main’: 13structtest.c:13:13: error: storage size of ‘a’ isn’t known 13structtest.c:13:13: warning: unused variable ‘a’ [-Wunused-variable]
you define the struct as xyx but you're trying to create the struct called xyz.
You define your struct as xyx
, however in your main, you use struct xyz a;
, which only creates a forward declaration of a differently named struct.
Try using xyx a;
instead of that line.
In this case the user has done mistake in definition and its usage.
If someone has done a typedef
to a structure the same should be used without using struct
following is the example.
typedef struct
{
int a;
}studyT;
When using in a function
int main()
{
struct studyT study; // This will give above error.
studyT stud; // This will eliminate the above error.
return 0;
}
Say it like this: struct xyx a;
correct typo of
struct xyz a;
to
struct xyx a;
Better you can try typedef, easy to b
1)declare the structs before the main function. it worked for me. 2) And also fix the spelling mistake of that variable name if any e
To anyone with who is having this problem, its a typo error. Check your spelling of your struct delcerations and your struct
Your struct is called struct xyx
but a
is of type struct xyz
. Once you fix that, the output is 100
.
#include <stdio.h>
struct xyx {
int x;
int y;
char c;
char str[20];
int arr[2];
};
int main(void)
{
struct xyx a;
a.x = 100;
printf("%d\n", a.x);
return 0;
}
Source: Stackoverflow.com