Logical errors in a Logical program

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include<fstream.h> //for file Input Output
#include<conio.h> // for clrscr() and getch()
#include<direct.h> // for mkdir()
#include<stdlib.h> // for exit()
#include<stdio.h> //for gets()
#include<string.h> //for string related functions
#include<ctype.h> // for toupper()
ifstream ifile;
ofstream ofile;
struct data
{
char *user_id;
char *user_name;
char *user_password;
char *security_ques;
char *security_ans;
char *account_name[99];
char *account_password[99];
char *account_note[99];
}in,out;
char ch,*temp1,*temp2;int x,user_check;
void main()
{
void Define();
void Menu();
clrscr();
ifile.open("C:\\PMANAGER\\DATA.MIC",ios::binary);
if(!ifile)
{
ifile.close();
Define();
}
ifile.close();
Menu();
}
void Define()
{
mkdir("C:\\PMANAGER");
ofile.open("C:\\PMANAGER\\DATA.MIC",ios::binary);
ofile.close();
}
void Menu()
{
void SignIn();
void SignUp();
clrscr();
cout<<"******************WELCOME TO MIC. PASSWORD MANAGER******************Version 1.00"<<endl;
cout<<"******************************************************Developed By:Pratik Ranjan"<<endl;
cout<<"******************************************************************Mic. Softwares"<<endl<<endl<<endl<<endl;
label1: cout<<"Enter 1. To Sign Up"<<endl;
cout<<"Enter 2. To Sign In"<<endl;
cout<<"Enter 3. To Exit"<<endl<<endl;
cout<<"Enter your choice: ";
cin>>ch;
switch(ch)
{
case '1': SignUp();
        break;
case '2': SignIn();
        break;
case '3': exit(0);
        break;
default: cout<<"Wrong choice"<<endl<<"Press any key to continue: ";
         getch();
         clrscr();
         goto label1;
}
}
void SignUp()
{
int CheckValidity(char *);
void SignIn();
cout<<endl<<"Enter your name: "<<endl;
gets(out.user_name);
label2: cout<<"Enter your desired username"<<endl;
gets(out.user_id);
x=CheckValidity(out.user_id);
if(x==1)
{
cout<<"Invalid username: "<<endl;
cout<<"1. Your Username must not contain space ''space'' in between"<<endl;
cout<<"2. Your Username must start with an alphabet"<<endl<<endl;
goto label2;
}
else if(x==2)
{
cout<<"Sorry Username already taken. Please choose a new username"<<endl;
goto label2;
}
label3: cout<<"Choose Password: ";
gets(temp1);
cout<<"Enter Password again: ";
gets(temp2);
if(strcmp(temp1,temp2)!=0)
{
cout<<"Your Password do not match, Please enter your password again"<<endl;
goto label3;
}
strcpy(out.user_password,temp1);
cout<<"Just in case you forget your password, enter a security question for account recovery"<<endl;
gets(out.security_ques);
cout<<"Enter the answer of the above question: ";
gets(out.security_ans);
ofile.open("C:\\PMANAGER\\DATA.MIC",ios::binary);
ofile.write((char*)&out,sizeof(out));
ofile.close();
cout<<endl<<"Congratulations, your account has been created"<<endl;
SignIn();
}
int CheckValidity(char* pa)
{
int i,j;
int check,length;
check=toupper(pa[0]);
if(!((check>=65)&&(check<=90)))
{
return 1;
}
length=strlen(pa);
for(i=0;i<length;i++)
{
if(pa[i]==' ')
return 1;
}
ifile.open("C:\\PMANAGER\\DATA.MIC",ios::binary);
while(!ifile.eof())
{
ifile.read((char*)&in,sizeof(in));
user_check=strcmp(in.user_id,pa);
if(user_check==0)
{
ifile.close();
return 2;
}
}
ifile.close();
return 0;
}
void SignIn()
{
data hitman;
cout<<"SignIn function is working"<<endl;
ifstream fin;
fin.open("C:\\PMANAGER\\DATA.MIC",ios::binary);
while(!fin.eof())
{
fin.read((char *)&hitman,sizeof(hitman));
cout<<"User name= "<<hitman.user_name<<endl;
cout<<"User password= "<<hitman.user_password<<endl;
cout<<"Security question= "<<hitman.security_ques<<endl;
cout<<"Security Answer= "<<hitman.security_ans<<endl;
}
}


First of all i am using Borland C++( Because I have to(in my school projects)..

so there are 2 errors...
1st in Line 125-136 That code is actually returning me 2.. But the algorithm clearly implies that since there is no data in the beginning, ther can't be a username existing on the file which matches the enterd username

2nd If I remove line 125-136.
there is another logical error in line 104-106... The data is not being written into the file?

Please Solve my problem.. Its very urgent for my school projects
Last edited on
Could you please use code tags around your code? The <> button on the right when you edit. I will not count to 125 to see where your error is.
Topic archived. No new replies allowed.