Thread: character strings

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    2

    character strings

    hi, im trying to make a structure made up of character strings. it looks like this:
    struct players
    {
    char pitcher[50];
    char catcher[50];
    etc...
    };

    however, when i try to give the strings a value:
    team1.pitcher="Babe Ruth";

    i get an error:
    '=' ; left operand must be 1-value

    anyone, please help me. i think the problem is the way i define the character strings. thanks.

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    give them a value like this,

    include this file string.h

    strncpy(team1.pitcher,"Babe Ruth",49);

    where 49 is the max number of characters to copy
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    No-one is right. And the reason why you got that error is that
    team1.pitcher is a char and "Babe Ruth" is a string. You can't assign a string to a char.

  4. #4
    Unregistered
    Guest
    hmmm...catcher[xyz] is an array. an arrays are a kind of direct pointers. catcher==&catcher==&(&catcher). Array can only initialized on definiton: 'catcher[50]="343"',, their address is set up on compilation and it cannot change on runtime! So "catcher=3433" is illegal! LValue required.

    etuli

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    2

    Talking

    it worked! thanks a lot!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 06:37 AM
  2. Character strings
    By campermama in forum C++ Programming
    Replies: 1
    Last Post: 06-17-2004, 04:26 PM
  3. character strings and reading in a file...
    By Unregistered in forum C Programming
    Replies: 14
    Last Post: 07-30-2002, 09:51 AM
  4. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM
  5. Array of character strings
    By nima_ranjbar in forum C++ Programming
    Replies: 1
    Last Post: 02-08-2002, 09:37 AM