Sorry if this is such a lame question, but I need help in getting this thing right. I've looked through countless resources, but none so far have granted to my favor.
I am working on a console version of an accounting program, specifically the basic password protection part.
This module divides into the following categories:
- main.cpp
- Password.cpp
- Password.h
The problem I have is narrowed down to the following functions:
Password.h/.cpp functions:
- char password[20];
- int SetPass();
- int GetPass(char *arg1);
My ultimate question and fustration is in trying to get the program to print the password on the console screen. When compiled and executed, all that is printed out is the first character of "google" (hence 'g'). I know I must be doing something wrong, I just do not know what exactly. If anyone may have the slightest idea as to this, help would be greatly appreciated. Thanks.
PS: For those inquiring why I do not use another variable type such as STRING, the success of my Password module depends on the specific use of char.
Password.h:
#include <stdio.h>
class Password {
private:
char password[20];
char *ptr; // not important
int GETCH(void); // not important
public:
int BreakPass(); // not important
int SetPass(char *arg1);
char GetPass();
};
Password.cpp function definitions:
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include "Password.h"
/*
Other function definitions omitted
*/
int Password::SetPass(char *arg1) {
strcpy_s(password, arg1); //copies arg. input to password variable
return 0;
}
char Password::GetPass() {
return *password; //returns password
}
main.cpp
#include <stdio.h>
#include <iostream>
#include <string.h>
#include "Password.h"
using namespace std;
int main()
{
Password pwd;
pwd.SetPass("google");
cout << pwd.GetPass(); // prints password to user
return 0;
}