Hello again, I'm having some difficulties with cin.getline() now. It seems when you use this function to input a string with spaces that you have to use it for every input value or your program will run through all the input fields and exit. I use char arrays since i still can't get string to work with my Dev C++. This is rather bothersome, especially in a loop where you need to input lots of different data. for example...
Code:
int available() {
for (int i=0;i<=23;i++) {
if (!player[i].active)
return i;
}
}
void input_player_data() {
int i=available();
cout << "Enter the group/player's reference name: ";
cin.getline(player[i].name, 30, '\n');
cout << "Enter number of players in the group: ";
cin >> player[i].quantity;
cout << "Enter the table they will be playing on: ";
cin >> player[i].table;
player[i].time_s = time(NULL);
tm *tmstruct = localtime( &player[i].time_s );
strftime( player[i].time_str, 30, "%I:%M %p", tmstruct ); // 12 hour time
player[i].active = 1;
}
In this sample, the function available() searches for a player slot that is "open" it then stores that in the int i and begins to start the inputing of the data. If I run this by itself it works just fine, but if i try to loop it with a menu before it, asking you what job you'd like to preform, it skips the name field anf starts on the quantity field. I believe it has something to do with the terminating character '\n' and the fact that without cin.getline(), input fields don't ignore '\n' and carry it over.
Thanks for your help ahead of time.
P.S. The menu i was talking about earlier looks like this:
Code:
cout << "1 -- Clock in a player or player group.\n";
cout << "2 -- List all current players/groups.\n";
cout << "3 -- Clock out players/groups.\n";
cout << "4 -- Divide a player group into a single player.\n";
cout << "5 -- Move the a group/player to a different table.\n";
cout << "6 -- Quick Figure a Time.\n";
cout << endl;
cout << "Enter the corresponding number to the action you wish to preform: ";
cin.getline(options, 5, '\n');
if (!strcmp(options,"1")){
input_player_data();}
else if (!strcmp(options,"2")){
list_players();}
else if (!strcmp(options,"3")){
clock_out_player();}
else if (!strcmp(options,"4")){}
//input_player_data();
else if (!strcmp(options,"5")){}
//input_player_data();
else if (!strcmp(options,"6")){}
//input_player_data();
else {
x = 0;
}