1)我需要從文件中讀字符串和字符串轉換爲一個鏈表字符串轉換爲一個鏈表
所以......如果我在這個字符串「一些字符串」
閱讀鏈表看起來像這樣
節點1 - 「S」
節點2 - 「O」
節點3 - 「M」
節點4 - 「e」 的
節點5 - NULL
node6 - 「S」
node7 - 「t」 的
node8 - 「R」
node9 - 「i」 的
node10 - 「n」
node11 - 「G」
node12 - NULL
NULL會爲 「」(空格)和 「\ 0」 空字符
發出最新最好的方式來實現這個..
typedef struct node
{
// each node holds a single character
char data;
// pointer to next node in linked list
struct node *next;
} node;
int i;
char buffer[1032];
FILE *ifp = fopen("file.txt", "rb");
//read the first line of file
fscanf(ifp, "%s", buffer);
node *myList = malloc(sizeof(node));
for(i = 0; i < strlen(buffer); i++)
/*I DON'T KNOW WHAT TO DO HERE!!!!*/
這裏我迷路了,或者,如果我完全錯了我的執行,請讓我知道
請記住標記你的問題與你使用的語言(這可能是C或C++)。 – Barmar
'/ *我不知道在這裏做什麼!!!! * /'?那麼,我會說,對於字符串中的每個字符,您需要創建並初始化節點,然後將列表的尾部指向新節點。 –