高人帮我看看这个程序错在哪里了

来源:百度知道 编辑:UC知道 时间:2024/05/29 17:27:56
#include "stdio.h"
#include "stdlib.h"
#include "iostream.h"

class UserManger
{
public:
UserManger();
virtual ~UserManger();
void ReadFiles(char *filename);
void user_login();
private:
char *user_id;
char *user_name;
char *user_pwd;
char *temp_id;
char *temp_name;
char *temp_pwd;
};

UserManger::UserManger()
{
temp_id=new char[10];
temp_id="NULL";
temp_name=new char[9];
temp_name="NULL";
temp_pwd=new char[16];
temp_pwd="NULL";
user_id=new char[10];
user_name=new char[9];
user_pwd=new char[16];
}

void UserManger::ReadFiles(char *filename)
{
FILE *fp=new FILE[100];
fp=fopen(filename,"or");
cout <<fp;
int n=sizeof(*fp);
char buffer[100];
fgets(buffer,100,fp);

for(int i=0;i<n

随便看了看,有至少2个问题

fp=fopen(filename,"or");
这个函数如果打开失败,你这个程序就死了
要判断如果fp为NULL,程序需要结束,或者做异常处理

还有
字符串匹配不能用==来

应该:
#include<string.h>

strcmp(str1,str)
如果等,返回0,否则非0

----------------------------
#include "stdio.h"
#include <string.h>
#include "stdlib.h"
#include "iostream.h"

class UserManger
{
public:
UserManger();
virtual ~UserManger();
void ReadFiles(char *filename);
void user_login();
private:
char *user_id;
char *user_name;
char *user_pwd;
char *temp_id;
char *temp_name;
char *temp_pwd;
};

UserManger::UserManger()
{
temp_id=new char[10];
temp_name=new char[9];
temp_pwd=new char[16];
user_id=new char[10];
user_name=new char[9];
user_pwd=new char[16];
}