
February 24th, 2013, 12:20 PM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
|
More specifically, you are not copying the string A into your struct with that assignment statement, but rather you are attempting a damned illegal thing: assigning a pointer value to an array name. That is why you got that error message.
Now, if you had declared Name to be a char pointer, you would not have gotten that error message, but you would still have made an enormous mistake. Because in that case, you would have assigned a char pointer, the address of A, to that char pointer in that struct and when A goes away when you leave that function then your struct will be pointing to garbage. And even if you made A a global or a static, then every time you called that function to enter a different name into a different struct, all structs' Name fields would immediately change to the new name input.
Instead, you need to copy the contents of A into Name. You need to use strcpy().
|