Start New Discussion within our Software Development Community

I have created an array of struct i am very frustrated beacuse I just can not figure out how to pass this array of struct into a function. here is my created struct and a general idea of what i have been trying

#include <stdio.h>

void functionOne(MyStruct)

struct MyStruct
{
    string IDname;
    int numbeOne;
    int numberTwo;
 };

int main()
{
MyStruct RecArray[100];

functionOne(RecArray);

return 0;
}

functionOne(MyStruct ArrayOfStruct[])
{
//function code
}

This works:

#include <stdio.h>
#include <string>
using namespace std;



struct MyStruct
{
    string IDname;
    int numbeOne;
    int numberTwo;
 };
 
void functionOne(MyStruct ArrayOfStruct[]);

int main()
{
MyStruct RecArray[100];

functionOne(RecArray);

return 0;
}

void functionOne(MyStruct ArrayOfStruct[])
{
//function code
}

Your original function declaration did not match your actual function (needed the void in the function and the brackets in the declaration. Also needed to include string library and the namespace, as well as add a semicolon. I don't think your problem was related to the fact that the object type was a struct except that you need to have your struct declaration before anything USING that struct (i.e. the function declaration).

This question has already been answered. Start a new discussion instead.