Thread: expected primary expressio before const

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    2

    expected primary expressio before const

    Code:
        case 2:
            cout << "\n Generating an eight number string...";
            numbers[0] = rand() % 9 + 0;
            numbers[1] = rand() % 9 + 0;
            numbers[2] = rand() % 9 + 0;
            numbers[3] = rand() % 9 + 0;
            numbers[4] = rand() % 9 + 0;
            numbers[5] = rand() % 9 + 0;
            numbers[6] = rand() % 9 + 0;
            numbers[7] = rand() % 9 + 0;
            strcat(rand_numb[0], const char*(numbers[0]));
            strcat(rand_numb[1], const char*(numbers[1]));
            strcat(rand_numb[2], const char*(numbers[2]));
            strcat(rand_numb[3], const char*(numbers[3]));
            strcat(rand_numb[4], const char*(numbers[4]));
            strcat(rand_numb[5], const char*(numbers[5]));
            strcat(rand_numb[6], const char*(numbers[6]));
            strcat(rand_numb[7], const char*(numbers[7])); 
            generate_password();
    I want to convert the numbers array (an int value) into a const char* array in order to add the string to rand_numb char array. When I try this it says expected primary expressio before "const". Don't know if it matters but I am using Dev-C++ (with MinGW) for my compiler.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You probably want to do a C-style cast, but since the destination type is consists of two words, you would need to use parentheses. However, I suspect that you are on the wrong track: you probably do not want to use strcat, and probably want to do this instead, where I demonstrate the use of static_cast instead of a C-style cast, and fix your +0 bug to +'0':
    Code:
    cout << "\n Generating an eight number string...";
    rand_numb[0] = static_cast<char>(rand() % 9 + '0');
    rand_numb[1] = static_cast<char>(rand() % 9 + '0');
    rand_numb[2] = static_cast<char>(rand() % 9 + '0');
    rand_numb[3] = static_cast<char>(rand() % 9 + '0');
    rand_numb[4] = static_cast<char>(rand() % 9 + '0');
    rand_numb[5] = static_cast<char>(rand() % 9 + '0');
    rand_numb[6] = static_cast<char>(rand() % 9 + '0');
    rand_numb[7] = static_cast<char>(rand() % 9 + '0');
    generate_password();
    Though why are you not passing rand_numb to generate_password()?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    2
    Though why are you not passing rand_numb to generate_password()?
    I probably forget, it was late at night.

    Thank you very much for your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fatal error LNK1104
    By DMH in forum C++ Programming
    Replies: 2
    Last Post: 11-16-2005, 03:46 AM
  2. Windows using Dev-C++
    By Renegade in forum C++ Programming
    Replies: 15
    Last Post: 07-07-2005, 08:29 PM
  3. Another overloading "<<" problem
    By alphaoide in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2003, 10:32 AM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  5. vector<>
    By teval in forum C++ Programming
    Replies: 11
    Last Post: 08-18-2003, 03:27 PM