Chào mọi người, em đang viết hàm để đăng kí tài khoản cho người dùng bằng C. Khi người dùng nhập username và pass thì ghi vào file. nhưng khi nhập chuỗi thì lại báo cái lỗi này. Ai tìm lỗi giúp với ạ. Em cảm ơn.
#include "stdafx.h"
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<windows.h>
struct user{
char username[50];
char pwd[50];
};
void sign_up(void)
{
user *p = NULL;
char pass[50];
FILE *f = fopen("user.bin", "wb");
if (f == NULL)
{
printf("Open error!");
return;
}
printf("Choose a username: ");
scanf("%s",&p->username);
printf("Choose a password: ");
scanf("%s",&p->pwd);
printf("Confirm password: ");
scanf("%s",&pass);
if (strcmp(p->pwd, pass) == 0)
{
printf("Sign up success!");
fwrite(p, sizeof(user), 1, f);
fclose(f);
}
else
{
printf("Password does not match!, please try again.");
sign_up();
}
}
int main()
{
sign_up();
_getch();
return 0;
}

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?