having issues with arrays of structs

So i keep trying different things to get an array to hold my structs and my latest has me trying to use pointers but kinda at a lost and need to be pointed in the right direction!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include <fstream>
using namespace std;
#include <cstring>
#include <cctype>

const int game_name = 35;
const int rating_of_game = 6;
const int platform = 30;
const int comments = 250;
const int summary = 400;
const int email = 35;


struct game_info
{
char name_of_game[game_name];
char game_rating[rating_of_game];
char game_platform[platform];
char game_comments[comments];
char summary_of_game[summary];
char email_address[email];
bool availability;
};


//prototypes
void readall(char prompt[], int max_size, char result[]);
void getting_game_info(*pointer);
char display(game_info & game, int i);




int main(){
   char filename[32]; // array to hold filename
   int num_games = 0; //array to hold number of games
   game_info * pointer= new game_info[20]; //array of my struct 
   //game_info single_game; //setting up variable for a single game
   char character; //character to set my loop up
   int i =0;
  

   getting_game_info(pointer); //calling function 
   display(single_game, i);
}

void readall(const char prompt[], int max_size, char result[])
{
	cout  <<prompt << '\n';
	cin.get(result, max_size, '\n');
	cin.ignore(100, '\n');
}	

void getting_game_info(*pointer)
{
    		
	char character;
           do {
	             readall("please enter name of game", game_name, pointer[i].name_of_game);
                 readall("please enter the rating of the game", rating_of_game, pointer[i].game_rating);
	             readall("please enter the game platform", platform, pointer[i].game_platform);
	             readall("please enter your comments about the game", comments, pointer[i].game_comments);
	             readall("please enter your summary of the game", summary, pointer[i].summary_of_game);
	             readall("please enter your email address", email, pointer[i].email_address);
        
                 cout <<"Is this information correct? Enter either y or n." << '\n';
                 cin >>character;
                 cin.ignore();
                 cout <<'\n';
           } while((character == 'n') || (character == 'N'));
           
     
}	
char display(game_info & game, int i)
{
	//for(int j=0;j=i;++j)
	//{
	cout <<"The name of the game is: "<<game[0].name_of_game << endl;
	cout << "The rating of the game is: "<<game[0].game_rating <<endl;
	cout <<"The game platform is: "<<game[0].game_platform <<endl;
	cout << "The game comments are: "<<game[0].game_comments <<endl;
	cout << "Summary of the game: "<<game[0].summary_of_game <<endl;
	cout << "Persons email address: "<<game[0].email_address <<endl;
    //}
}



On line 55 you forgot "game_info" before the pointer asterisk.
so i am still getting errors now

"44 30 [Error] cannot convert 'game_info' to 'game_info*' for argument '1' to 'void getting_game_info(game_info*)'


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

#include <iostream>
#include <fstream>
using namespace std;
#include <cstring>
#include <cctype>

const int game_name = 35;
const int rating_of_game = 6;
const int platform = 30;
const int comments = 250;
const int summary = 400;
const int email = 35;


struct game_info
{
char name_of_game[game_name];
char game_rating[rating_of_game];
char game_platform[platform];
char game_comments[comments];
char summary_of_game[summary];
char email_address[email];
bool availability;
};


//prototypes
void readall(char prompt[], int max_size, char result[]);
void getting_game_info(game_info *pointer);
char display(game_info & game, int i);




int main(){
   char filename[32]; // array to hold filename
   int num_games = 0; //array to hold number of games
   game_info * pointer= new game_info[20]; //array of my struct 
   //game_info single_game; //setting up variable for a single game
   char character; //character to set my loop up
   int i =0;
  

   getting_game_info(*pointer); //calling function 
   display(*pointer, i);
}

void readall(const char prompt[], int max_size, char result[])
{
	cout  <<prompt << '\n';
	cin.get(result, max_size, '\n');
	cin.ignore(100, '\n');
}	

void getting_game_info(game_info *pointer)
{
    		
	char character;
           do {
           	     for(int i=0;i < 20;++i){
	             readall("please enter name of game", game_name, pointer[i].name_of_game);
                 readall("please enter the rating of the game", rating_of_game, pointer[i].game_rating);
	             readall("please enter the game platform", platform, pointer[i].game_platform);
	             readall("please enter your comments about the game", comments, pointer[i].game_comments);
	             readall("please enter your summary of the game", summary, pointer[i].summary_of_game);
	             readall("please enter your email address", email, pointer[i].email_address);
          }
                 cout <<"Is this information correct? Enter either y or n." << '\n';
                 cin >>character;
                 cin.ignore();
                 cout <<'\n';
           } while((character == 'n') || (character == 'N'));
           
     
}	
char display(game_info *pointer)
{
	//for(int j=0;j=i;++j)
	//{
	cout <<"The name of the game is: "<<pointer[0].name_of_game << endl;
	cout << "The rating of the game is: "<<pointer[0].game_rating <<endl;
	cout <<"The game platform is: "<<pointer[0].game_platform <<endl;
	cout << "The game comments are: "<<pointer[0].game_comments <<endl;
	cout << "Summary of the game: "<<pointer[0].summary_of_game <<endl;
	cout << "Persons email address: "<<pointer[0].email_address <<endl;
    //}
}

At line 45, you're de-referencing the pointer:

 
   getting_game_info(*pointer); //calling function 

That means that you're trying to pass the actual object into the function, rather than a pointer.
Last edited on
On line 45 you should not dereference the pointer - remove the asterisk. Why did you change this from before? Your previous code had line 44 correct.
Last edited on
Haha, i am not sure i fixed that right before i saw this post! It is working now !!! Thanks all!
Topic archived. No new replies allowed.