Hello,
I'm just getting used to suctures, and I'm a bit confused. I can't find out how to initialize a string. Say in the eample structure:
struct school {
char first[20];
char second[20];
char third[20];
} teachers;
How can " teachers.first " be initialized to " Johnson "?
I've tried " *teachers.first = ... " but that creates one letter and then garbage values. Is there a problem in the structure definition?
Am I accessing the member incorrectly? What is wrong?
Comments
: I'm just getting used to suctures, and I'm a bit confused. I can't find out how to initialize a string. Say in the eample structure:
:
: struct school {
: char first[20];
: char second[20];
: char third[20];
: } teachers;
:
: How can " teachers.first " be initialized to " Johnson "?
: I've tried " *teachers.first = ... " but that creates one letter and then garbage values. Is there a problem in the structure definition?
: Am I accessing the member incorrectly? What is wrong?
:
strcpy(teachers.first, "Johnson");
: : I'm just getting used to suctures, and I'm a bit confused. I can't find out how to initialize a string. Say in the eample structure:
: :
: : struct school {
: : char first[20];
: : char second[20];
: : char third[20];
: : } teachers;
: :
: : How can " teachers.first " be initialized to " Johnson "?
: : I've tried " *teachers.first = ... " but that creates one letter and then garbage values. Is there a problem in the structure definition?
: : Am I accessing the member incorrectly? What is wrong?
: :
:
:
: strcpy(teachers.first, "Johnson");
:
In order to use [b]strcpy( , )[/b], you also need the header file [b]#include[/b]
: : : I'm just getting used to suctures, and I'm a bit confused. I can't find out how to initialize a string. Say in the eample structure:
: : :
: : : struct school {
: : : char first[20];
: : : char second[20];
: : : char third[20];
: : : } teachers;
: : :
: : : How can " teachers.first " be initialized to " Johnson "?
: : : I've tried " *teachers.first = ... " but that creates one letter and then garbage values. Is there a problem in the structure definition?
: : : Am I accessing the member incorrectly? What is wrong?
: : :
: :
: :
: : strcpy(teachers.first, "Johnson");
: :
:
: In order to use [b]strcpy( , )[/b], you also need the header file [b]#include[/b]
:
:
or: [b]#include [/b]
: : : : I'm just getting used to suctures, and I'm a bit confused. I can't find out how to initialize a string. Say in the eample structure:
: : : :
: : : : struct school {
: : : : char first[20];
: : : : char second[20];
: : : : char third[20];
: : : : } teachers;
: : : :
: : : : How can " teachers.first " be initialized to " Johnson "?
: : : : I've tried " *teachers.first = ... " but that creates one letter and then garbage values. Is there a problem in the structure definition?
: : : : Am I accessing the member incorrectly? What is wrong?
: : : :
: : :
: : :
: : : strcpy(teachers.first, "Johnson");
: : :
: :
: : In order to use [b]strcpy( , )[/b], you also need the header file [b]#include[/b]
: :
: :
: or: [b]#include [/b]
:
Thank you very much, working exactly right now.
: I'm just getting used to suctures, and I'm a bit confused. I can't find out how to initialize a string. Say in the eample structure:
:
: struct school {
: char first[20];
: char second[20];
: char third[20];
: } teachers;
:
: How can " teachers.first " be initialized to " Johnson "?
: I've tried " *teachers.first = ... " but that creates one letter and then garbage values. Is there a problem in the structure definition?
: Am I accessing the member incorrectly? What is wrong?
:
uh, ever think of making a CONSTRUCTOR???