I've been making a program for fun and I'm an amateur programmer too. I added a feature to a program that let's it read users externally from files to log in instead of storing user data on the code so that new users can register.
I'm having problems in line 13 and 14 when putting the root of where the user files are where /" makes the ; become part of the string too and invalid.
Also, in line 40 it gives me the error of invalid conversion between const char* to char, please help me!
Last bu not least, how can make it so that the files with user names and passwords and secret and no one can see them and can it work if I don't put .txt in the end of the file name?
#include <iostream>
#include <cstring>
#include <conio.h>
#include <fstream>
using namespace std;
void calc();
void loop();
void fbase();
char user[25];
char pass[25];
char userpath[30] = "user\";
char userpasspath[30] = "user\";
int u = 0;
int main()
{
cout<<"Cenu Alpha v0.2\n\n";
for ( ; u == 0; u++) {
cout<<"User: ";
cin>>user;
strcat (userpath, user);
strcat (userpasspath, user);
strcat (userpasspath, "pass");
ifstream userfile ( userpath );
ifstream userpassfile ( userpasspath );
if (userfile == user) {
cout<<"Password: ";
cin>>pass;
if (pass == userpassfile) {
cout<<"\nWelcome, signed in as "<< user <<".\n\n";
} else {
cout<<"Wrong password. Quitting...";
getch();
return 0;
}
} else {
cout<<"\nUser unkown, signed in as guest.\n\n";
user[0] = "g";
}
}
int choice;
cout<<"What would you like to use?\n\n";
cout<<"1. Calculator\n";
cout<<"2. Function Database\n";
cout<<"3. Exit\n\n";
cout<<"Selection: ";
cin>>choice;
cout<<endl;
cin.ignore();
switch (choice) {
case 1:
calc();
break;
case 2:
fbase();
break;
case 3:
cout<<"Thank you for running Cenu Alpha v0.2!";
break;
default:
cout<<"Invalid selection. Please try again.\n\n";
main();
break;
}
cin.get();
}
void calc()
{
int num1;
int num2;
cout<<"Calculator\n\nFirst Number: ";
cin>>num1;
cin.ignore();
cout<<"Second Number: ";
cin>>num2;
cin.ignore();
cout<<endl<<num1<<"+"<<num2<<"="<<num1+num2<<"\n";
getch();
main();
}
void fbase() {
int choice;
cout<<"Function Database\n";
cout<<"Welcome to the funcion database. It contains complex forgetable functions.\n\n";
cout<<"1. String Functions\n";
cout<<"2. Other general funcions\n";
cout<<"3. Back\n\n";
cout<<"Selection: ";
cin>>choice;
cout<<"\n";
switch (choice) {
case 1:
cout<<"1. #include <cstring>\n";
cout<<"2. int strcmp( string, string)\n";
cout<<"3. char strcat( destination, source)\n";
cout<<"4. char strcpy( destination, source)\n";
cout<<"5. size_t strlen( source)\n\n";
cout<<"Selection: ";
cin>>choice;
cout<< endl;
switch (choice) {
case 1:
cout<<"#include <cstring>\n";
cout<<"This is the header file for many string funcions.\n\n";
getch();
fbase();
break;
case 2:
cout<<"int strcmp( string 1, string 2)\n";
cout<<"Negative if s1 is less than s2.\n";
cout<<"Zero if s1 and s2 are equal.\n";
cout<<"Positive if s1 is greater than s2.\n\n";
getch();
fbase();
break;
case 3:
cout<<"char strcat( destination, source)\n";
cout<<"Must if string is char: charname[0] = '\0'\n";
cout<<"Adds source to end of destination.\n\n";
getch();
fbase();
break;
case 4:
cout<<"char strcpy( destination, source)\n";
cout<<"Makes destination same as source. (Untested)\n\n";
getch();
fbase();
break;
case 5:
cout<<"int size_t strlen( source)\n";
cout<<"Resturns the length of the source string.\n\n";
getch();
fbase();
break;
default:
cout<<"Invalid selection. Please try again.\n\n";
getch();
fbase();
break;
}
break;
case 2:
cout<<"1 = True. 0 = False";
cout<<"Not (!). False to true and true to false.\n";
cout<<"And (&). If both are right, return 1, if not, then false.\n";
cout<<"Or (||). If any of the numbers are 1, return 1.\n";
getch();
fbase();
break;
case 3:
main();
break;
default:
cout<<"Invalid selection. Please try again.\n\n";
getch();
fbase();
break;
}
}