properly, are being interpreted properly (the loop stops after typing a

\n

) and the cast is being done properly, but the assignment is not working. For what it is worth, I also tried making

linked_list.data

a regular

char

and assigning directly (via

current->data = input_cast

) and received similar results (blank output, rather than

(null)

, implying a

\0

was "printed"). I presume this is some nitpicky point about structs that I am not familiar with, but I can't for the life of me figure out what it is. Feel free to grab/compile/test the code as you please.

Also, I am aware there is a memory leak... this is a modified snippet from a larger body of code, so many features are not academic perfection. I just wanted to demonstrate the behavior I was getting.

Thanks everybody!

EDIT: As noted below, the error was that I was trying to print the char of my current node AFTER I had switched to the next, empty node. Stupid logic error on my part.

You need to allocate 2 bytes, like this: current->data = malloc(2);First bytes will store you character and second byte will store string terminator '\0', after that you can print it as a string. You forget to use your previous field you can: