K
Kay
This function is used getline function to get data. The data is stored
as String. I want to add it in a linked list. However, the strcpy that I
have pointed cause the program segementation fault. What I can do to
add the item in the linked list and it don't need to change the Linked
list ADT item type ?
void load(istream& is, Position p, List * r )
string temp_name;
//get the restaurant name in restaurnat.txt
while ( getline(is, temp_name, '\n')) {
char *name;
//change type of name of restaurant from string to char
name = new char[temp_name.length() + 1 ];
strcpy( name, temp_name.c_str()); <-- This one
char *namet;
p = ListHead(r);
namet = (char *)malloc(sizeof(name));
strcpy (namet, name);
//Add the namet in the linked list
if (!rest_get_name(r, p, namet)) {
exit (EXIT_FAILURE);
}
as String. I want to add it in a linked list. However, the strcpy that I
have pointed cause the program segementation fault. What I can do to
add the item in the linked list and it don't need to change the Linked
list ADT item type ?
void load(istream& is, Position p, List * r )
string temp_name;
//get the restaurant name in restaurnat.txt
while ( getline(is, temp_name, '\n')) {
char *name;
//change type of name of restaurant from string to char
name = new char[temp_name.length() + 1 ];
strcpy( name, temp_name.c_str()); <-- This one
char *namet;
p = ListHead(r);
namet = (char *)malloc(sizeof(name));
strcpy (namet, name);
//Add the namet in the linked list
if (!rest_get_name(r, p, namet)) {
exit (EXIT_FAILURE);
}