I have a simple function that adds a node to a linked list:
This works fine, I get output in this form:Code:node *x = new node;
cout << "enter value" << endl;
cin >> x -> value;
x -> next = head;
head = x;
Quote:
node: a
node: b
node: c
node: d
node: e <- I entered this value via the function
but when I pass the value to the function via string val
output is likeCode:node *x = new node;
cout << "val[0] = " << val[0] << endl; // prints e
val[0] = x -> value;
x -> next = head;
head = x;
What is wrong?Quote:
node: a
node: b
node: c
node: d
node: 8 <- should be e
PS. value (in node) is of type char.