Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7682939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:40:57+00:00 2026-05-31T18:40:57+00:00

I am working on a program and part of it requires me to create

  • 0

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. I had numerous problems with this code and had lots of help from here but need a little more. I can’t output the populated struct to the screen. If anyone could help me with this last thing I would be so grateful!

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;
};

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


int main()
{
 struct DETAILS David;

 fillperson(struct DETAILS David, "David Greene", 38, 180.0);

 cout<<David.name<<endl;
 cout<<David.age<<endl;
 cout<<David.height<<endl;

 return 0;
}

DETAILS fillperson(struct DETAILS David, char name[LEN], int age, double height) 
{
 cout<<"Done"<<endl;
 return;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:40:58+00:00Added an answer on May 31, 2026 at 6:40 pm
    DETAILS fillperson(David, "David Greene", 38, 180.0); //deprecated conversion from string constant to char * [-Wwrite-Strings]
    

    This is because string literals (like “David Greene”) are const, and you’re passing it as just a char[LEN]. Try const char[LEN].

    DETAILS fillperson(struct DETAILS, char[LEN] name, int age, double height) //expected , or ... before 'name'
    

    The [] goes after the name of the variable: char name[LEN].

    Also, where is this David variable coming from? The name of the variable needs to be in the function signature (struct DETAILS David, not just struct DETAILS).

    cin>>David.name>>name;
    

    I think what you really want is:

    DETAILS fillperson(struct DETAILS David, const char name[LEN], int age, double height)
    

    EDIT:

    I think you misunderstood what I was saying. This line is a weird mix of function definition of function call.

    DETAILS fillperson(struct DETAILS David, "David Greene", 38, 180.0);
    

    When you call a function, you don’t declare types:

    fillperson(David, "David Greene", 38, 180.0);
    

    But you do need them in the actual function definition, so instead of this:

    DETAILS fillperson(struct DETAILS, char[LEN] name, int age, double height) 
    

    Do this:

    DETAILS fillperson(struct DETAILS David, char name[LEN], int age, double height)
    

    EDIT 2:

    Also, I don’t know what you’re trying to do here (or any of the similar lines):

    cin>>David.name>>name;
    

    Are you trying to copy the string? (See strncpy) or read input (cin >> David.name)?

    Recommendation

    If you’re using C++ and C++ input streams, you should really just use string.

    EDIT 3

    Your current code won’t work for several reasons:

    DETAILS fillperson(struct DETAILS David, char name[LEN], int age, double height) 
    {
        cout<<"Done"<<endl;
        return;
    }
    

    The function signature says the function returns DETAILS (the first part of the line), but you don’t return anything. Either return the input struct:

    return David;
    

    Or make the method return void (nothing):

    void fillperson(...
    

    My recommendation about using string is that it’s much easier to work with than straight character arrays (char[]):

    string name = “David”;
    string name2 = name; // Copying is much easier

    So for example, your code could look like this:

    #include <cstdlib>
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    struct DETAILS
    {
        string name;
        int age;
        double height;
    };
    
    // Note that I'm passing a reference for DETAILS (the &). This means
    // that we have access to the actual DETAILS instance from outside
    // the method, not just a copy.
    void fillperson(struct DETAILS&, const string, int, double);
    
    int main()
    {
        struct DETAILS David;
    
        fillperson(David, "David Greene", 38, 180.0);
    
        cout<<David.name<<endl;
        cout<<David.age<<endl;
        cout<<David.height<<endl;
    
        return 0;
    }
    
    void fillperson(struct DETAILS &person, const string name, int age, double height) 
    {
        person.name = name;
        person.age = age;
        person.height = height;
        cout<<"Done"<<endl;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the last part of the program I am working on. I want
We're working on a group assignment. Part of the program is for the use
I'm trying to get a simple winsock program working, so I create my socket
I have a working Python based program that I want to run as a
I am working on a program in C as a part of Homework in
There is a slight part of my program that is not working correctly and
I've been working on a console based Inventory program as part of my course,
im working on a part of program where i need to send null to
I am working on implementing a simulated annealing program and part of this involves
Im working on a two part program that uses an encoder do encode a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.