将字符串转换为双链表的节点

时间:2018-09-07 13:49:07

标签: c arrays string linked-list

我想知道是否可以将字符串转换为链接列表 例如,“ hello \ nhi \ nhey \ n \ 0”打招呼->嗨->嘿-> NULL 每个节点都是一个字符串。

到目前为止,这是我的代码,我不确定如何将其转换为链接列表。请告诉我我的方向是否正确。谢谢

typedef struct node{
    char *text;
    struct node *prev;
    struct node *curr;
    struct node *next;
 } Node;

 Node newNode(char text[]) {
    struct Node *Line = malloc(sizeof(struct Node));
    assert(Line != NULL);
    int lineCount = 0;
    int lineLength = strlen(text);
    int i = 0;

    while(i < lineLenght) {
        if(text[i] == '\n') {
             lineCount++;
             // do i need to add more?????
        }
        i++;
     }
      // i'm not sure what i should do here....
      return newNode;
 }

0 个答案:

没有答案
相关问题