Functions and Structures

I have to write two functions for a structure:
#1 function which will return a reference to a Part structure and receive a reference to a Part structure. It will change the Description to EEPROM; the Cost will be 1.95; the ID will be 123456; Type will be E.

#2 function making the same data changes as above, but have the function receive a pointer and return nothing, using pointer notation throughout the function.

When I try to change the Description to equal EEPROM in the functions I get an error. If someone can help me I would appreciate it.

Thanks,
R.

Here is some of the code:

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
 #include <iostream>
#include<cstdlib>
#include<time.h>

using namespace std;


struct Part
{
	char Description[30];
	double Cost;
	long ID;
	char Type;

};

Part & ChangeDes(Part &p);
void ChangeDes(Part *p);

int main()
{
 Part Widget;

ChangeDes(Widget);


system("pause");
	return 0;
}
Part & ChangeDes(Part &p)
{
	p.Description = 'EEPROM';
	p.Cost = 1.95;
	p.ID = 123456;
	p.Type = 'E';

	return p;
}

void ChangeDes(Part *p)
{
	p->Description = 'EEPROM';
	p->Cost = 1.95;
	p->ID = 123456;
	p->Type = 'E';
}
You should not quote more than one char with single quotes ('). Use double quotes (").
It is important to understant, that Description is not of type char. It is char[], so the literal notation is a bit different.

Edit: Oh, how silly of me. I got a bit rusty with C++, it seems. A problem is a bit more complex than that:
http://stackoverflow.com/questions/579734/assigning-strings-to-arrays-of-characters
Last edited on
Thank you JockX for your quick reply. I was able to solve the error. Thank for your help.
R.
Topic archived. No new replies allowed.