我正在尝试将用户添加到链接列表中。我有两个结构和一个方法来添加名为add_friend的设置节点的添加。程序不要求用户输入,而是通过add_friend方法中的参数传递信息:除了将节点(用户)添加到列表中,我必须检查用户是否已经存在。当我尝试比较字符串以查看用户是否存在时,出现错误。任何帮助?不幸的是C是我最弱的编程语言,我很难理解指针在链接列表中添加节点
struct UserAccountNode{
struct UserAccount* content;
char circle;
struct UserAccountNode* next;
}*head = NULL ;
struct UserAccount{
char username[255];
char lastnm [256];
char firstnm[256];
char password[256];
char gender;
int phone;
struct Post* post_list;
struct UserAccountNode* friend_list;
} ;
int add_friend(UserAccount* user, char Circle, UserAccount* Friend)
{
struct UserAccountNode* friend_list;
friend_list = (struct UserAccountNode*) malloc (sizeof(struct UserAccountNode));
while (friend_list != NULL)
if (stricmp(Circle, head->friend_list) == 0)
{
friend_list -> next = head;
head = friend_list;
}
else{
printf("%d, User Already Exists", Friend);
}
return 0;
}
如果这是[的解剖**这**](http://stackoverflow.com/questions/22627293/adding-a-new-user-to-list-in-c-program)的后果,你需要放下StackOverflow并拿起你的课本。认真。 *停止编写代码,花一些时间研究和阅读它。*没有捷径。 – WhozCraig
你想如何确定朋友是否已经在列表中?你能否检查一个具有相同地址的用户是否已经存在? – pat