谁能帮我看看一点c语言的小问题
这个是要实现通讯录的注册功能 如果有重复注册就会显示此人已经注册可是我的为什么每次运行 即使注册过了 还是能写到文件中 总是没办法走while判断的语句
是我哪里写的问题 求高人指点 我的qq希望能有c语言高手加我一下 不胜感激
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct USER
{
char loginName[20];
char loginPass[20];
struct USER *pUserNext;
}User;
typedef struct Linker
{
int id;
char name[20];
char phone[20];
char address[20];
}Linker;
User* creatList();
User* registerUser(User *pUserHead);
FILE *fileOpen(const char *fileName,const char *mode);
int main()
{
User *p = creatList();
if(NULL == registerUser(p))
{
printf("注册失败\n");
}
else
{
printf("注册成功\n");
}
}
//注册
User* registerUser(User *pUserHead)
{
FILE *pfw = fileOpen("user.txt","ab");
User *jitou = pUserHead;
User *regUser = (User*)malloc(sizeof(User));
printf("请输入用户名:");
scanf("%s",regUser->loginName);
printf("\n");
printf("请输入用户密码:");
scanf("%s",regUser->loginPass);
printf("\n");
if(NULL == pUserHead)
{
regUser->pUserNext = NULL;
fwrite(regUser,sizeof(User),1,pfw);
fclose(pfw);
return regUser;
}
while(pUserHead)
{
if(strcmp(regUser->loginName,pUserHead->loginName) == 0)
{
free(regUser);
fclose(pfw);
printf("该用户名已经注册\n");
}
pUserHead = pUserHead->pUserNext;
}
regUser->pUserNext = jitou;
fwrite(regUser,sizeof(User),1,pfw);
fclose(pfw);
return regUser;
}
//创建
User* creatList()
{
FILE *pfr = fopen("朱凯通讯录.txt","wb");
User *tou = NULL,
*wei,
*temp;
temp = (User*)malloc(sizeof(User));
while(fread(temp,sizeof(User),1,pfr))
{
temp->pUserNext = NULL;
if(NULL == tou)
{
tou = temp;
}
else
{
wei->pUserNext = temp;
}
wei = temp;
temp = (User*)malloc(sizeof(User));
}
free(temp);
fclose(pfr);
return tou;
}
FILE *fileOpen(const char *fileName,const char *mode)
{
FILE *pf = fopen(fileName,mode);
if(NULL == pf)
{
pf = fopen(fileName,"wb");
fclose(pf);
pf = fopen(fileName,mode);
}
return pf;
}