我需要採取以下代碼,並將其修改爲接受字符串作爲參數,而不是整數。最後,我需要程序獲取所有命令行參數,並將它們添加到字符串的鏈接列表中。C - 字符串鏈接列表
所以如果輸入是六七八,當我打印鏈表時,它會打印:八七六。
#include <stdio.h>
#include <stdlib.h>
typedef struct iNode
{
int myInt;
struct iNode* next;
} IntNode, *IntNodePtr;
IntNodePtr insert(int i, IntNodePtr p)
{
IntNodePtr newp = malloc(sizeof(struct iNode));
newp->myInt = i;
newp->next = p;
return newp;
}
printlist(IntNodePtr p)
{
if(p == NULL)
printf("\n");
else
{
printf("%d ", p->myInt);
printlist(p->next);
}
}
main(int argc, char* argv[])
{
int n = 5;
if(argc > 1)
n = atoi(argv[1]);
IntNodePtr iNodeList;
iNodeList = NULL;
int i = 0;
while(i < n)
{
iNodeList = insert(i++, iNodeList);
printf("List is now: ");
printlist(iNodeList);
}
}
那麼究竟是什麼問題呢? – 2011-02-07 01:46:59
閱讀[SO常見問題解答](http://meta.stackexchange.com/questions/10811/how-to-ask-and-answer-homework-questions)。 – outis 2011-02-07 01:58:36