Hi, I am trying to retrieve data from the CSV file. I am creating linked list to copy that data.
temp = (Signal_Config*)malloc(sizeof(Signal_Config)); // allocate space
i cant alllocte memory for this. because i am using that members as string in struct.(please see the header file). i tired to initialize members as char pointer, i cant covert that string data to char pointer.(i tired to use c_str)
i am beginner. i want to save these string data. Please help.
}
else
{
Signal_Config *temp; // create a temporary
temp = (Signal_Config*)malloc(sizeof(Signal_Config)); // allocate space
temp->FAILURE_TYPE = Buffer_Data[0];
temp->Signal_Discription = Buffer_Data[1];
temp->CAN_ID = Buffer_Data[2];
temp->Start_Bit = Buffer_Data[3];
temp->Bit_Length = Buffer_Data[4];
temp->Bit_Value = Buffer_Data[5];
temp->CAN_ID_Discription = Buffer_Data[6];
temp->next=head; // store the address of the pointer head(second field)
head = temp;
Number_of_Signals++;
}
}
if (Discription_list == config_list)
{
data_avail = 1;
}
}
temp1 = head;
while( temp1!=NULL )
{
cout<< temp1->FAILURE_TYPE<<" ";
cout<< temp1->Signal_Discription<<" ";
cout<< temp1->CAN_ID<<" "; // show the data in the linked list
cout<< temp1->Start_Bit<<" ";
cout<< temp1->Bit_Length<<" ";
cout<< temp1->Bit_Value<<" ";
cout<< temp1->CAN_ID_Discription<<" ";
cout<< "\n";
temp1 = temp1->next; // tranfer the address of 'temp->next' to 'temp'
}
cout<<endl<<"Number of Signals: "<<Number_of_Signals<<endl;
Did you try using new, which is the C++ way of allocating memory, rather than malloc.
temp = new Signal_Config;
I was trying to understand the CSV data, but there were no comma separators in the sample data shown above. I was also wondering, is that the entire file, or will it contain data for multiple vehicles. Also do you have to use a linked list, wouldn't an array or vector do?