Ok for some reason when I passed both a string and an integer only the recent value will be called when I use the "GET" command. For example I would type in "SET name=alan" and when I would use the "GET" function I would of course call the value alan. But when I SET another member I cannot get back the "name" member value. I would just get the value of the most recent member that was set. Here is the code, I think I am passing the strings wrong or I need a copy constructor, please help me:
Code:
#include <iostream>
//#include <cstdlib>
#include <string>
#include <stdio.h>
using namespace std;
char * arrbName;
char * pch;
// string input2;
char * varName;
class Info
{
public:
Info();
string getName();
void setName(const string& user_name);
// string getStreet();
// void setStreet(const string& user_street);
int getAge();
void setAge(int num);
// int getID();
// void setID(int num2);
private:
string Name;
string Street;
int age;
int id;
};
Info::Info()
{
Name="";
Street="";
age=0;
// id=0;
}
string Info::getName()
{
return Name;
}
void Info::setName(const string& user_name)
{
Name = user_name;
}
/*string Info::getStreet()
{
return Street;
}
void Info::setStreet(string user_street)
{
Street = user_street;
}*/
int Info::getAge()
{
return age;
}
void Info::setAge(int num)
{
age = num;
}
void main()
{
Info information;
char command1[] = "SET";
char command2[] = "GET";
char command[3];
char input1[] = "name"
char input2[] = "street";
char input[30];
int index;
while(1)
{
printf(": ");
scanf("%s %s", command,input);
if(strcmp (command1,command) == 0)
{
pch = strtok(input, " =");
arrbName = pch;
pch = strtok(NULL, " =");
if(pch == NULL)
{
cout<<"ERROR commandline is incomplete"<<endl;
exit(1);
}
else
varName = pch;
if(arrbName == "name" || "Name")
{
string stringName = varName;
// information.setName(stringName);
information.setName(stringName);
}
else if(arrbName == "age" || "Age")
{
// string streetName = varName;
int i = atoi(varName);
information.setAge(i);
}
else
cout<<"ERROR the property name does not match with out members"<<endl;
}
else if(strcmp (command2,command) == 0)
{
if(input == "name" || "Name")
{
cout<<information.getName()<<endl;
}
else if(input == "age" || "Age")
{
cout<<information.getAge()<<endl;
}
else if(input =="*")
{
cout<<"name: "<<information.getName()<<endl;
cout<<"age: "<<information.getAge()<<endl;
}
else
cout<<"ERROR the property name does not match with out members"<<endl;
}
else
cout<<"ERROR the command line is not reconized"<<endl;
}
}