Structure problems. . .

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

  • : 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?
    :


    strcpy(teachers.first, "Johnson");
  • : : 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?
    : :
    :
    :
    : strcpy(teachers.first, "Johnson");
    :

    In order to use [b]strcpy( , )[/b], you also need the header file [b]#include[/b]

  • : : : 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?
    : : :
    : :
    : :
    : : strcpy(teachers.first, "Johnson");
    : :
    :
    : In order to use [b]strcpy( , )[/b], you also need the header file [b]#include[/b]
    :
    :
    or: [b]#include [/b]
  • : : : : 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?
    : : : :
    : : :
    : : :
    : : : 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.
  • : 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?
    :
    uh, ever think of making a CONSTRUCTOR???

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories