我有一个双向链表,能够在每个节点中保存字符。这就是我向每个节点输入字符的方法。
printf("Enter string of characters for the list: ");
scanf("%s",s);
for(i=0;s[i]!='\0';i++)
Insert(s[i],&Header1);
现在我希望修改列表以在每个节点中存储单词。用户提供的输入是一个句子。如何确保每个单词(用空格分隔)进入列表的节点?
最佳答案
while ( sscanf( sentence, "%s", &node_value ) == 1 )
{
//Call to insert into your list goes here
//Each pass node_value will be the next word
}
注意:您必须将 node_value
按值传递到您的列表中,否则您的所有值都将是相同的引用!
关于c - 如何将单词输入到链接列表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13085464/