I just reproduce the example #include <iostream.h> struct student { int stnumber; char *stname; char *stsex; }; int main() { student stu; return 0; }
to access the structs' members, use the . notation. Code: stu.stnumber = some_value; Code: struct student { char *stname; char *stsex; int stnumber; }; struct student stu; you've got the same issue as with the other topic regarding char *... they're pointers that point to nothing; if you try to use them that way, you'll likely crash your program. to use them to hold data, you need to allocate some space or assign them to an existing char array[some_size]. Code: stu.stname = new char[20]; // allocate some space stu.stsex = new char[10]; // allocate some space // do something with stu.stname // do somehting with stu.stsex delete [] stu.stname; // clean up memory allocated delete [] stu.stsex; if you don't really understand new and delete right now, then create two static arrays for stname and stsex. Code: struct student { char stname[20]; char stsex[10]; int stnumber; }; struct student stu; or typedef struct { char stname[20]; char stsex[10]; int stnumber; } student; student stu;