Populate struct values with function argument

Posted by adohertyd on Stack Overflow See other posts from Stack Overflow or by adohertyd
Published on 2012-03-22T17:22:50Z Indexed on 2012/03/22 17:30 UTC
Read the original article Hit count: 337

Filed under:

I am working on a program and part of it requires me to create a struct called DETAILS with the fields name, age, and height. I want to populate the record with data using a function argument. When I run my code I get compiler errors. I have put the errors in comment form beside the lines it is returned for but I can't fix them. Really could do with some help here guys thanks so much.

Here is my code:

#include <cstdlib>
#include <iostream>
#include <iomanip>

using namespace std;

const int LEN=100;

struct DETAILS
{
 char name[LEN];
 int age;
 double height;
};

 person fillperson(struct DETAILS, char[LEN], int, double);


int main()
{
 struct person David;

 fillperson(David, "David Greene", 38, 180.0); //deprecated conversion from string constant to char * [-Wwrite-Strings]

}

person fillperson(struct DETAILS, char[LEN] name, int age, double height) //expected , or ... before 'name'
{
  cin>>David.name>>name;
  cin>>David.age>>age;
  cin>>David.height>>height;

 cout<<"Done"<<endl;
}

© Stack Overflow or respective owner

Related posts about c++