NarenderKumarP 0 Newbie Poster

Hi Lerner,
Thanks! So far I have done the same. My next step is to match the value till couple of columns in a row and if 2 rows are almost similar the value for the row which matches more closer should be displayed.

A glimpse of my code

for (int i=0; i<r; i++)
 {
    if( matrix_points[i][0] == ACE_Wide_To_Ascii(wEcuId.c_str()).char_rep()) 	   
    {
     printf("\nEntered");
     printf(matrix_points[i][1]);
    if(atoi(matrix_points[i][1]) == functionID)  		 
    {
     printf("Entereted functionID\n");
     if(matrix_points[i][2] == ACE_Wide_To_Ascii(testID.c_str()).char_rep()) // Comparing TestId in Excel file with the input TestId
     {	
       printf("Entered testID\n");
      if(atoi(matrix_points[i][3]) == testStat)  // Comparing TestStatus in Excel file with the input TestStatus
    {
     printf("Entered testStatus\n");
    if(atoi(matrix_points[i][4]) == ev.getNewState())  //Comparing ResponseType in Excel file with ErrorEvent's ResponseType
     {
      printf("Entered ResponseType\n");
     if(matrix_points[i][5] == ev.getEvent())  //Comparing ResponseCode in Excel file with ErrorEvent's ResponseCode
     {
      printf("Entered ResponseCode\n");
      qStrCT = matrix_points[i][6];
      printf(qStrCT);
     ACE_WString wStrCT ((const ACE_WCHAR_T *) qStrCT.unicode(), qStrCT.length());
     ACE_TString tStrCT = ACE_Wide_To_Ascii(wStrCT.c_str()).char_rep();
     ct = wStrCT;

      //Retrieving Defaulttext
     qStrDT = matrix_points[i][7];
     printf(qStrDT);
     ACE_WString wStrDT ((const ACE_WCHAR_T *) qStrDT.unicode(), qStrDT.length());
     ACE_TString tStrDT = ACE_Wide_To_Ascii(wStrDT.c_str()).char_rep();
     dt = wStrDT;			
   //LOGI1(ACE_TEXT("Veena:matrix_points[i][7] change to ACE_WSTRING.[%s]"),ACE_Wide_To_Ascii(wStr.c_str()).char_rep());
  }
  else
 {
      qStrCT = matrix_points[i][6];
      printf(qStrCT);
     ACE_WString wStrCT ((const ACE_WCHAR_T *) qStrCT.unicode(), qStrCT.length());
     ACE_TString tStrCT = ACE_Wide_To_Ascii(wStrCT.c_str()).char_rep();
     ct = wStrCT;

      //Retrieving Defaulttext
     qStrDT = matrix_points[i][7];
     printf(qStrDT);
     ACE_WString wStrDT ((const ACE_WCHAR_T *) qStrDT.unicode(), qStrDT.length());
     ACE_TString tStrDT = ACE_Wide_To_Ascii(wStrDT.c_str()).char_rep();
     dt = wStrDT;			
   //LOGI1(ACE_TEXT("Veena:matrix_points[i][7] change to ACE_WSTRING.[%s]"),ACE_Wide_To_Ascii(wStr.c_str()).char_rep());
      }
     }
    }
   }			 
  }
 }
}

Thanks & Regards

NarenderKumarP 0 Newbie Poster

Hi Dragon,
Thank you. Actually I am able to manipulate the values from the csv file based on the row,column concept. I have now need to manipulate the values based on the header names. Concept being same as last, I would like to query based on column names.

Thanks & Regards,
Narender

NarenderKumarP 0 Newbie Poster

This is what my whole code looks like. I am unable to locate the constructor which would help store into my codeText variable(ACE_WString) the value of matrix_points(QString). As you see the paramter in the function of my application requires me to pass ACE_WString type. Basically I want to assign QString type value to ACE_WString variable.

Follwoing is the error

C:\NDA\NissanNewApplication\Dev\CommonErrorManager\Src\CCommonErrorManager.cpp(193) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class QString' (or there is no acceptable conversion)


int CCommonErrorManager::requestErrorHandling(ErrorEvent& ev, ACE_WString& codeText, ACE_WString& defaultText, int& functionID,ACE_WString& testID, int& testStat)
{

    QString matrix_points[6][8];
    //std::ifstream input_file("C:/NDA/NissanNewApplication/Dev/CommonErrorManager/Src/ErrorMessageList.csv");
    std::ifstream input_file("../../Src/ErrorMessageList.csv");

  char line[255];
input_file.clear();
  input_file.seekg(0);

int r = 0, c = 0, colcnt = 0;
QString linecol, field;

while(input_file.getline(line, sizeof(line), '\n'))  // to read  lines
{
    linecol = line; 
    while(linecol != "")
    {           
        //linecol = linecol.stripWhiteSpace(); 
        int pos = linecol.find(',');            
        if(pos > 0)
        {

            //linecol = linecol.left(pos);  // substr function does not work in VC++. 
            matrix_points[r][c] = linecol.mid(0,pos);
            //printf(matrix_points[r][c]);
            //printf(" ");
            linecol = linecol.mid(pos+1);
            c++;
        }
        else
        {
            matrix_points[r][c] = linecol;
            //printf(matrix_points[r][c]);
            linecol = "";
            colcnt = c;
            c = 0;
            r++;
            printf("\n");
        }                   
    }
}

//Retrieving Value
ACE_WString wStr = codeText;
ACE_TString tStr = ACE_Wide_To_Ascii(wStr.c_str()).char_rep();

   for (int i=0; i<r; i++)             
     if(matrix_points[i][0] == "ECU_MODEL_KWP_ABS")
       {
            //printf(matrix_points[i][3]+" " );
            //printf(matrix_points[i][6]+" " );
            //printf(matrix_points[i][7] + "\n");

         [QUOTE]codeText = matrix_points[i][6];[/QUOTE]
         //codeText (const char *matrix_points[i][6], ACE_Allocator *alloc = 0);

       }


    //Initializing the output parameters codeText & defaultText. Both of these need to be searched in the database.
    //codeText = L"";
    defaultText …
NarenderKumarP 0 Newbie Poster

Hi Dragon,
Thanks for the reply. It works. Now the problem comes when I assign the matrix_points, which is of type QString to a variable in my application which is of ACE_WString Type, it gives a problem. What kind of typecasting method can we apply to overcome it?

Thanks & Regards,
Narender

NarenderKumarP 0 Newbie Poster

Hi,
Yeah line is character array. This is how the following code looks like. Can you please find the area with mistakes and correct it.

QString matrix_points[6][8];
char line[255];
std::ifstream input_file("C:/NDA/NissanNewApplication/Dev/CommonErrorManager/Src/ErrorMessageList.csv");

input_file.clear();
input_file.seekg(0);

int r = 0, c = 0;

QString linecol, field;

while(input_file.getline(line, sizeof(line), '\n'))  // to read  lines
{
    while(line != "")
    {
        linecol = line;
        //linecol = linecol.stripWhiteSpace(); 
        int pos = linecol.find(',');
        field = linecol.left(pos);
        if(pos > 0)
        {           
            linecol = linecol.left(pos);  // substr function does not work in VC++. 
            matrix_points[r][c] = linecol;
            printf(matrix_points[r][c]);
            linecol = linecol.left(pos+1);
            ++c;
        }
        else
        {
            matrix_points[r][c] = line;
            linecol = "";
            c = 0;
            r++;
        }           
    }
}
NarenderKumarP 0 Newbie Poster

This(following) is the code I am using which is almost same as yours. Certain c functions are not working in VC++ like push_back, substr etc. Still output is always the first field, i.e. ECU ID in the format above.
Can you please send me the code more in the line of VC++(if not C++ is also OK)

QString linecol;

while(input_file.getline(line, sizeof(line), '\n'))  // to read  lines
{
    while(line != "")
    {
        linecol = line;
        int pos = linecol.find(',');
        field = linecol.left(pos);
        if(pos > 0)
        {

            linecol = linecol.left(pos);  // substr function does not work in VC++. 
            matrix_points[r][c] = linecol;
            printf(matrix_points[r][c]);
            linecol = linecol.left(pos+1);
            ++c;
        }
        else
        {
            matrix_points[r][c] = line;
            linecol = "";
            c = 0;
            r++;
        }           

    }

}

Thanks & Regards,
Narender

NarenderKumarP 0 Newbie Poster

Actually yesterday I just copied the content from csv file as it is and therefore looked to be tab/space separated file. Following is the correct format
ECU ID,Function ID,Test ID,Test Status,Response Type,Response Code,codeText,defaultText
*,*,*,*,*,*,Default,Default
ECU_MODEL_KWP_ECCS,4,WS-2-1,*,*,*,1,Emergency stop
ECU_MODEL_KWP_ABS,3,AT-2-01,*,*,*,2,Stop test
ECU_MODEL_CAN_ABS,4,WS-2-1,*,*,*,3,Adjustment finished
ECU_MODEL_CAN_LDW,4,WS-1,*,*,*,4,Stop

Here how do I know the end of line.
I want to read all the value in 2D array and then extract conditionally in the for loop.


Hi Dragon,
This is how the csv file looks

ECU ID FuncID TstID TstStatus ResType ResCode codeTxt deftText
* * * * * * Default Default
ECU_MODEL_KWP_ECCS 4 WS-2-1 * * * 1 Emergency stop
ECU_MODEL_KWP_ABS 3 AT-2-01 * * * 2 Stop test
...
...
As of now I have 6 rows and 8 columns. In future rows may increase and column might also change. So how can we make it dynamic. But first I want my static one to work. Would appreciate your support in this regard.

Narender

Its a VC++ compiler and gives the following message

error C2440: '=' : cannot convert from 'char [255]' to 'char'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast

NarenderKumarP 0 Newbie Poster

I am facing a problem while assigning the line value to two dimensional array.
So how should I assign the value of line variable to the two dimensional array as follows

Basically I want to read all the values in the matrix. Based on these values I have to conditionally replace the values in my application. That is for a given row I want to find the value of particular field in the row and then extract the the value of other field in the same row using the matrix(2-D array). Here is my

int matrix_points[6][8];


std::ifstream input_file("C:/NDA/NissanNewApplication/Dev/CommonErrorManager/Src/ErrorMessageList.csv");


char line[255];


input_file.clear();
input_file.seekg(0);
int r = 0, c = 0;


while( input_file.getline(line, sizeof(line), ','))
{
matrix_points[r][c] = (char)atoi(line);
++c;
if( c == 8)
{
r++;
c = 0;
}
}


//Retrieving Value


for (int i=0; i<r; i++)
for(int j=0; j<c; j++)
{
printf("%s", matrix_points);
}

Error comes when I assign the value of line to matrix array and when I try to display the value of this matrix with specific dimension. E.g matrix_points[1][7]

So basically the problem is : storing the value in matrix_points and extracting the values

No error is displayed but I don’t get the expected output.

NarenderKumarP 0 Newbie Poster

This is the format

ECU ID Function ID Test ID Test Status Response Type Response Code codeText defaultText
* * * * * * Default Default
ECU_MODEL_KWP_ECCS 4 WS-2-1 * * * 1 Emergency stop
ECU_MODEL_KWP_ABS 3 AT-2-01 * * * 2 Stop test
ECU_MODEL_CAN_ABS 4 WS-2-1 * * * 3 Adjustment finished
ECU_MODEL_CAN_LDW 4 WS-1 * * * 4 Stop

NarenderKumarP 0 Newbie Poster

Hi Dragon,
This is how the csv file looks

ECU ID FuncID TstID TstStatus ResType ResCode codeTxt deftText
* * * * * * Default Default
ECU_MODEL_KWP_ECCS 4 WS-2-1 * * * 1 Emergency stop
ECU_MODEL_KWP_ABS 3 AT-2-01 * * * 2 Stop test
...
...
As of now I have 6 rows and 8 columns. In future rows may increase and column might also change. So how can we make it dynamic. But first I want my static one to work. Would appreciate your support in this regard.

Narender

Its a VC++ compiler and gives the following message

error C2440: '=' : cannot convert from 'char [255]' to 'char'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast

>>Following code gives me an error when I use text field in CSV file instead of float or integer fields

what compiler? post the errors. The compiler should give you warnings that it is converting int to char and may lose data.

what does the csv file look like -- can you post the first two or three lines? Are the values between -127 and 126 because that is the range of signed char. If the csv file contains larger numbers then you will have to redeclare the matrix as a 2d array of ints, not chars

int matrix_points[6][8];

and the while loop is incorrect. use of eof() is unpredictable.

// while(!(input_file.eof()))
//{
while( input_file.getline(line, sizeof(line), ',') > …
NarenderKumarP 0 Newbie Poster

Hi All,
Following code gives me an error when I use text field in CSV file instead of float or integer fields.

matrix_points[cnt][4] = atoi(line);
May be the problem with above line. Please see the below code

char matrix_points[6][8];



std::ifstream input_file("C:/NDA/NissanNewApplication/Dev/CommonErrorManager/Src/ErrorMessageList.csv");
int cnt(0);
printf("initial valie of cnt = %d\n",cnt);
char buffer[256];
char line[255];



input_file.clear();
input_file.seekg(0);


while(!(input_file.eof()))
{
input_file.getline(line, sizeof(buffer), ',');
matrix_points[cnt][0] = line;
//printf(" %s", line);


input_file.getline(line, sizeof(buffer), ',');
matrix_points[cnt][1] = atoi(line);
//printf(" %s", line);



input_file.getline(line, sizeof(buffer), ',');
matrix_points[cnt][2] = atoi(line);
//printf(" %s", line);


input_file.getline(line, sizeof(buffer), ',');
matrix_points[cnt][3] = atoi(line);
//printf(" %s", line);


input_file.getline(line, sizeof(buffer), ',');
matrix_points[cnt][4] = atoi(line);
//printf(" %s", line);


input_file.getline(line, sizeof(buffer), ',');
matrix_points[cnt][5] = atoi(line);
//printf(" %s", line);


input_file.getline(line, sizeof(buffer), ',');
matrix_points[cnt][6] = atoi(line);
//printf(" %s", line);


input_file.getline(line, sizeof(buffer), ',');
matrix_points[cnt][7] = atoi(line);
//printf(" %s", line);
cnt++;
}


for (int i=0; i<cnt; i++){


printf("%s", matrix_points[0]);
printf("  %s", matrix_points[1]);
printf("  %s", matrix_points[2]);
printf("  %s", matrix_points[3]);
printf("  %s", matrix_points[4]);
printf("  %s", matrix_points[5]);
printf("  %s", matrix_points[6]);
printf("  %s\n", matrix_points[7]);
}
NarenderKumarP 0 Newbie Poster

Here length is static. But generally we do not know the length of the field so it sounds a bit not practical.


#include<iostream>
#include<fstream>
using namespace std;

int main()
{
  //don't start BIG!!!!!
  int row = 2;  //number of lines
  int col = 2;  //number of fields
  int len = 10;  //maximum number of char in any given field

  int r, c; 
  ifstream fin("myFile.csv");//open file
  if(!fin)                           //confirm file opened
    cout << "unable to open file;" << endl;
  else
  {
    char *** input;        //declare an array to store input using dynamic memory
    input = new char**[row];
    for(r = 0; r < row; ++r)
    {
       input[r] = new char*[col];
       for(c = 0; c < col; ++c)
          input[r][c] = new char[len];
    }
     
    //put something into the array   
    for(r = 0; r < row; ++r)
       for(c = 0; c < col; ++c)
           fin.getline(inputl[r][c], 9, ',');

   //do something with the information in the array        
   for(r = 0; r < row; ++r)
      for(c = 0; c < col; ++c)
         cout << input[r][c] << ' ';         
 }
 return 0;
}

//=============
myFile.csv
//=============
Billy,loves
Bobby,Sue

This demonstrates how you might read a csv file into a dynamically declared table of strings separating strings by field and line and then do something with it. Once you proved the concept, then expand it. For example, try to read in just the first couple fields of your file, then the first line, then the first 10 lines, etc. adjusting the appropriate variables to expand the scope of …

NarenderKumarP 0 Newbie Poster

Hi,
I wanted to read text field and atoi is giving a problem. I cannot use
matrix_points[row][col] = atoi(line);
which is good for integer/float values

If I write
matrix_points[row][col] = line;
it gives an error

Please suggest me what changes could I make

NarenderKumarP 0 Newbie Poster

Hello Everyone,
This is Narender. I am a new member in your community. Hope all cooperation from you all.

Thanks & Regards,
Narender