Pergunta

i'm trying to make this some more compact:

while (res->next())
{
    strcpy(laArray[i][1],res->getString(1).c_str());
    strcpy(laArray[i][2],res->getString(2).c_str());
    strcpy(laArray[i][3],res->getString(3).c_str());
    strcpy(laArray[i][4],res->getString(4).c_str());
    strcpy(laArray[i][5],res->getString(5).c_str());
    strcpy(laArray[i][6],res->getString(6).c_str());
    strcpy(laArray[i][7],res->getString(7).c_str());
    strcpy(laArray[i][8],res->getString(8).c_str());
    i++;
}

i've come up with this but it aint working: (it freezes at startup)

while (res->next())
{
    for (int j=0; j < 3; j++){
        strcpy(laArray[i][j],res->getString(j).c_str());
    }
    i++;
}

Thank you for your time

Foi útil?

Solução

Your loop has the wrong initial and ending values

while (res->next())
{
    for (int j=1; j <= 8; j++){
        strcpy(laArray[i][j],res->getString(j).c_str());
    }
    i++;
}

Also, I'd look very closely at why you are using 1-based indexing rather than 0-based which is the idiom in C++: the first element of an array is at index 0.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top