passingg struct by reference help

keep getting an error by doing it this way, what am i doing wrong?

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
  #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 read(char prompt, int max_size, char result[]);
void getting_game_info(game_info &);

int main(){

void getting_game_info(game_info &);
}

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

void getting_game_info()
{
	game_info game;
	read("please enter name of game", game_name, game.name_of_game);
    read("please enter the rating of the game", rating_of_game, game.game_rating);
	read("please enter the game platform", platform, game.game_platform);
	read("please enter your comments about the game", comments, game.game_comments);
	read("please enter your summary of the game", summary, game.summary_of_game);
	read("please enter your email address", email, game.email_address);
}	
Last edited on
What error are you getting and what is your expected result. I find this code confusing on a level that I am not sure if I am missing some complex programming technique used in C++, or simply you made a basic mistake of mistaking fuction declaration with function call.
this is my error [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]

what i am trying to do is use the read function to basically be a function that simplifies things for me, so i do not have to prompt the user and ask for input each time
Then i use the getting_game_info function calling the read function to receive the info from the user.

i am likely making a really mistake with the function call part haha.
Is there any reason you can't use std::string instead of C-style strings (arrays of char)?
http://www.cplusplus.com/reference/string/string/
professor does not want us using strings yet.
Change your main() function to(?):

1
2
3
4
5
6
int main() {
	game_info ginfo;
	getting_game_info(ginfo);
	std::cin.get();
	return 0;
}
not sure where the ginfo came from ?
but tried putting my struct variable inside the getting_game_info()
that did not work
Change
void read(char prompt[], int max_size, char result[])
to
void read(const char prompt[], int max_size, char result[]).

Also, your function prototypes don't match their definitions.

In main(), you should call getting_game_info like this:
1
2
3
4
5
int main()
{
    game_info game;
    getting_game_info(game);
}

Also, remove the game variable from inside your getting_game_info function (line 44 in your code above).
Thanks!
Topic archived. No new replies allowed.