Resizing ArrayDadosEx.members into the loop eliminated the error. [smile]
Quote:
I'm not sure what your assignments in the inner loop are trying to do. I assume you are assigning values to ArrayDadosEx[0]'s members somewhere in your ...'s. Given that your inner loop then seems to propegate these values up through the entire array, I'd suspect it would be clearer to just assign to the whole array in a loop when you assign to [0], although I don't know what else is going in in the ...'s, so I may be off track.
I really need to do ArrayDadosEx.roboID[rob] = ArrayDadosEx[i-1].roboID[rob] in the inner loop. To understand better, please take look at my complete function:
VOID AlimentaArrayDadosEx(){ ArrayDadosEx.resize(nroLinhas); BYTE roboID_linha; FLOAT x_linha; FLOAT y_linha; FLOAT theta_linha; BOOL carreg_linha; // Alimentando o array de dados for ( DWORD i = 0 ; i < nroLinhas ; i++ ) { ArrayDadosEx.carregado.resize(nroRobos); ArrayDadosEx.roboID.resize(nroRobos); ArrayDadosEx.x.resize(nroRobos); ArrayDadosEx.y.resize(nroRobos); ArrayDadosEx.theta.resize(nroRobos); // tempo do sistema for (int j = 0 ; j < 7 ; j++ ) fscanf(mFile, "%d", &ArrayDadosEx.tempo); // agv fscanf(mFile, "%d", &roboID_linha); // state (pula) fscanf(mFile, "%s", stringTemp); // x,y, theta fscanf(mFile, "%f", &x_linha); fscanf(mFile, "%f", &y_linha); fscanf(mFile, "%f", &theta_linha); // node (pula) fscanf(mFile, "%s", stringTemp); // loaded fscanf(mFile, "%d", &carreg_linha); // Alimentando o array for ( BYTE rob = 0 ; rob < nroRobos ; rob++ ) { if ( roboID_linha == rob + 1 ) { ArrayDadosEx.roboID[rob] = roboID_linha; ArrayDadosEx.x[rob] = x_linha; ArrayDadosEx.y[rob] = y_linha; ArrayDadosEx.theta[rob] = theta_linha; ArrayDadosEx.carregado[rob] = carreg_linha; } else { if ( i > 0 ) { ArrayDadosEx.roboID[rob] = ArrayDadosEx[i-1].roboID[rob]; ArrayDadosEx.x[rob] = ArrayDadosEx[i-1].x[rob]; ArrayDadosEx.y[rob] = ArrayDadosEx[i-1].y[rob]; ArrayDadosEx.theta[rob] = ArrayDadosEx[i-1].theta[rob]; ArrayDadosEx.carregado[rob] = ArrayDadosEx[i-1].carregado[rob]; } } } // Indo para a próxima linha while ( fgetc(mFile) != '\n' ) { } } fclose(mFile); }
Basically, I'm extracting data from a MatLab file and storing the values in the ArrayDadosEx. The file contains positions (x,y,theta) of 5 robots. There are 10869 lines, so that each line stores the system time, the position of a robot and the ID of this robot. There is no orderly sequence of the robots' ID along the file.
I created the ArrayDadosEx because my application needs to know the positions of all robots at each line of the file, that is, if a line is referred to robot whose ID = 3, at this same time, I need to know the positions of the other robots.