char arrays ---- i forgot

This is a discussion on char arrays ---- i forgot within the C++ Programming forums, part of the General Programming Boards category; Could somebody please help me, I am having a total brain fart. I have a variable named: char buff[20]; I ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    16

    char arrays ---- i forgot

    Could somebody please help me, I am having a total brain fart.

    I have a variable named: char buff[20];
    I need to put strings into that char array, but I cannot just stuff a string into it, or use the .c_str() conversion of string. I dont want to have to address each location like this: buff[0] = 'a'; buff[1] = 'b';

    Does anybody have any help for me?? Please I hope so.

    - Brice

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    16
    I forgot to say this. The char array is part of a class and it doesnt get modified until after a variable of that class hase been defined. Then, thought the rest of the program that char array will continue to get changed. Thanks again

    - Brice

  3. #3
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    If it is not a dynamicly allocated array than do this:

    char buf[10][20];

    This will allow you to use 10 arrays of 20 characters each. If the member variables are public than:

    strcpy(object.buf[0], "This string");

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    16
    I do not have a need for an array of character arrays, I just needed to put some text inside of an existing char buf[12]. the strcopy(object.buf, "text here") worked great for my problem though! Thanks a lot for your help

    - Brice

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  2. Wierd Segmentation Faults on Global Variable
    By cbranje in forum C Programming
    Replies: 6
    Last Post: 02-19-2005, 12:25 PM
  3. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 12:58 PM
  4. comparing fields in a text file
    By darfader in forum C Programming
    Replies: 9
    Last Post: 08-22-2003, 09:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21