-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Sat, 8 Nov 2003 14:41:59 +0000
Gedi
Hi Jerry,
I have just started on pointers and passing by address a few days ago.
The first problem you pointed out was a silly mistake on my part. I should have noticed that. I guess spotting silly mistakes like that will become second nature in time.
The second issue makes sense now. Thanks for taking the time to explain Hopefully it will work. However, if you want to use pointers: void student_info(struct students *data); void print(struct students *data);
replace:
student[i] = student_info(student[i]);
with:
student_info(&student[i]);
The in student_info, replace data. by data-> as below:
cin.getline (data->name, 30);
Do the same thing in print.
Note that since you are using a pointer to the student structure in
student_info(), you do not need to return anything. (But you might want
to report success or failure).
Additionally, you could pass the structure into the two functions by
using the C++ pass by reference. That would require only changes to the
function prototypes and definitions:
struct students &student_info(struct students &data);
Also note that in C++, a struct is the same thing as a class with all
functions and data public. Your struct actually has a default
constructor. In the case of your program, it really does not matter.
But, student_info() could be moved into the struct and renamed as the
constructor, but you probably have not studied classes yet.
- --
Jerry Feldman