Thread: C++ builder 6 help needed

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    1

    C++ builder 6 help needed

    Can anybody help with this problem i have with bcb ver6.

    I have a simple program, with an array of strings. There are 100 words in this array. the array is in a function called get_a_word. Then in the T Form object i have a char word[20]. I randomly select a word and copy it into the both the hidden_word and words strings. T
    This works fine once, but once i call the function again if the previous word was longer than the one now selected the program, leaves the remaining characters in place e.g. first word = Hello, second word = Hi , whats in string = Hillo.
    I have tried using the strcpy(words,"") to clear the string first, but it doesnt seem to clear correctly. I am calling this from the get_a_word function. Sample of code below.

    Can anybody help me?

    Att

    //code for program //

    TForm1 *Form1;

    char words[20];
    char hidden_word[20];

    //-------------------------------
    TForm1::get_a_word()
    {
    int size, x, y;
    char wordlist[20][20]=
    {
    //word list here
    };
    strcpy(word,"");
    strcpy(hidden,"");
    }

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Sorry, but I don't think I can help you with this. I need more code to see what's going wrong. Here's an example that works:
    Code:
    char words[20];
    char wordlist[5][20] = { "Hello", "Hi", "world", "Ho Ho", "STOP" };
    
    strcpy(words, wordlist[0]);
    printf("word = [%s]\n", words);
    
    strcpy(words, wordlist[1]);
    printf("word = [%s]\n", words);
    If you need to clear the string you can use this:
    Code:
    words[0] = '\0';

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. free needed or not?
    By quantt in forum Linux Programming
    Replies: 3
    Last Post: 06-25-2009, 09:32 AM
  2. THE END - Borland C++ Builder, Delphi, J Builder?
    By Davros in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 02-28-2006, 11:23 PM
  3. Converting from Borland Builder -> MSVC++ guide?
    By _Elixia_ in forum Windows Programming
    Replies: 4
    Last Post: 08-02-2003, 09:00 AM
  4. C++ builder 6 (program opening)
    By Demon1s in forum C++ Programming
    Replies: 4
    Last Post: 04-07-2003, 04:08 AM
  5. Borland C Help needed (Locales)
    By Bill 101 in forum C Programming
    Replies: 0
    Last Post: 11-13-2002, 01:04 PM