【发布时间】:2014-03-25 21:40:33
【问题描述】:
我正在尝试将用户添加到链接列表。我有两个结构和一个名为 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;
}
【问题讨论】:
-
如果这是the dissection of this的后果,你需要放下StackOverflow,拿起你的课本。严重地。 停止编写代码,花点时间研究和阅读它。没有捷径可走。
-
您想如何确定好友是否已在列表中?您可以检查是否已经存在具有相同地址的用户吗?
标签: c struct linked-list nodes