I think i need to use a pointer, some help please...
When i got to the chapter on pointers in my book, i just put it down, i couldnt follow it. As far as i know a pointer is something that holds the location of a variable, correct? Well here's my program, i figured out a login scheme that i think is excellent, i think its irreversible. Ok the problem is i dont want everything to be inside one infinite loop, things get too clustered, so i want the login to be in one while(1){} loop and the actual program to be in another. The problem is i need 2 variables from the 1st loop to be used to access the second. Any help would be greatly appreciated.
Code:
#include <iostream>
#include <fstream>
#include <windows.h>
#include <string>
using namespace std;
int main()
{
/*
Database program for Blacksquadron
Auther: Doug Daly
Version: 1.00
*/
//Universal Vars
//infinite loop
while(1)
{
//title
cout<<"**************************\n";
cout<<"* Black Squadron *\n";
cout<<"* Database *\n";
cout<<"**************************\n\n";
//login
//init all vars
char username[25];
char password[25];
char encinfo[25];
char tempenc[25];
char tempencI[25];
char tempencII[25];
int xleng;
int i;
//get information
cout<<"Username: ";
cin.getline(username, 25);
cout<<"Password: ";
cin.getline(password, 25);
cout<<"\nPress enter to begin encryption...\n";
cin.ignore();
//encrypt
for(i=0; i<25; i++)
{
tempenc[i]=username[i]+password[i];
}
xleng = strlen(tempenc);
if((xleng%2)!=0)
{
tempenc[xleng+1]='x';
xleng = strlen(tempenc);
}
for(int j=0; j<(xleng/2); j++)
{
tempencI[j]=tempenc[j];
}
i=0;
for(int k=(xleng/2); k<xleng; k++)
{
tempenc[i]=tempenc[k];
i++;
}
for(int l=0; l<(xleng/2); l++)
{
encinfo[l]=tempencI[l]^tempencII[l];
}
//convert non-standard characters to standard
for(int m=0; m<(strlen(encinfo)); m++)
{
encinfo[m]=char(((int(encinfo[m]))%26)+65);
}
//END ENCRYPTION
//check result with known result
//get import variables
char ch;
char importloc[100]="C:/Documents and Settings/Douglas/My Documents/C++/Test/known.cmc";
char importcode[16];
i=0;
//import
ifstream fin(importloc);
while(fin.get(ch))
{
importcode[i]=ch;
i++;
}
fin.close();
//evaluate
//eval. vars
int evalnum=0;
int encleng;
//evaluate both known and new info
if(strlen(importcode)==strlen(encinfo))
{
encleng=(strlen(encinfo));
}else{
cout<<"Length Mismatch\n";
continue;
}
for(i=0; i<encleng; i++)
{
if(encinfo[i]==importcode[i])
{
evalnum++;
}
}
if(evalnum==encleng)
{
cout<<"Successful Login!\n";
break;
}else{
cout<<"Incorrect Login Information...\n";
}
}
//check login correct
if(evalnum==encleng)
{
//another infinite loop
while(1)
{
//Program refresh
system("cls");
//title
cout<<"|BS|BS|BS|BS|BS|BS|BS|BS|BS|BS|BS|BS|BS|BS|BS|\n";
cout<<"|BS| DATABASE |BS|\n";
cout<<"|BS|BS|BS|BS|BS|BS|BS|BS|BS|BS|BS|BS|BS|BS|BS|\n\n";
//menu
}
}
return 0;
}