Ok I was going along in my book as usual. I was at the 2nd to last page of the Structure and Union chapter when I wrote this code from the example in the book:
There are no compiler errors or errors in the actual code that I typed out. However, when I run this program it asks for my name, I type in a name. Then a Windows box pops up saying that the program has caused in error in MSVCRT.DLL and wiill now close. On the box there was a debug option that opened up Visual C++ and I debugged it and it said it was having access violation problems writing to the address (I am thinking whatever addressAll quoted text is copyright Computer Step 2004 and is taken from the book C Programming in Easy Steps by Mike McGrath
Code:#include <stdio.h> typedef struct { union { int num; char letter; }; char *name; } info; int main() { /* create a struct of the info type */ info stored; printf("Please enter your first name: "); gets( stored.name ); printf("Enter a number to convert to hex? [Y or N]: "); scanf("%c", &stored.letter); if( stored.letter == 'y' || stored.letter == 'Y') { printf("OK, enter the number to be converted: "); scanf("%d", &stored.num ); printf("Thanks %s, ", stored.name ); printf("%d in hex is 0x%X\n", stored.num,stored.num); } return 0; }is being stored in). I've never encountered this sort of error before as a programmer, and was just wondering how to get around it. ANd yes, I did try rebooting my computer like it said in the error box. Thanks for the help.Code:stored.name