Hi everyone,
Please be patient as I am a confused beginner
I have been working through the excellent C beginners' tutorial on this site and have thoroughly enjoyed it, but I seem to have become stuck on lesson 7, Structures. The problem is that I cannot get the example program to compile either in Visual C++ Express 2005 nor MinGW Developer Studio. With both compilers I get a series of six errors basically complaining about undeclared identifiers in relation to the newly created structs. At first I thought I must have miskeyed the code, but even a straight copy and paste spews the same errors. For convenience I've posted the short code below and I'd be much obliged if anyone can spot my mistake.
Thanks in advance, Steve
Code:
#include <stdio.h>
struct xampl {
int x;
};
int main()
{
xampl structure;
xampl *ptr;
structure.x = 12;
ptr = &structure; /* Yes, you need the & when dealing with
structures and using pointers to them*/
printf( "%d\n", ptr->x ); /* The -> acts somewhat like the * when
does when it is used with pointers
It says, get whatever is at that memory
address Not "get what that memory address
is"*/
getchar();
}