Click here to Skip to main content
14,921,505 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

The following is basically C but I'm just wondering how I might create a function declaration so that I could pass the structure array to that function and use that function to fill the structure array.

I've looked at a few examples but none seem to work. Should I be declaring student in a different way (if so what would the function declaration be)?

Code is here:
int main()
{
	

	struct Student{
		string name;
		int id;
		string courseCode;
	};

	
	Student *student;
	student = new Student[3];
Posted
Comments
Sergey Alexandrovich Kryukov 16-Feb-13 19:47pm
   
Why not just learning the language before asking such questions? Or do you want learn by asking? It won't be effective...
—SA
BrianHamilton 17-Feb-13 14:32pm
   
Your statement makes no sense - if everyone learned the language (learning the language as you put it) - there would be no need for this site. No-one is required to reply to any question and I do not believe I have broken any site rules.

1 solution

Hi,
You have to pass the size of the array also as a parameter.

C++
struct Student{
	string name;
	int id;
	string courseCode;
};

void ProcessStudent(Student * stu[], int Cnt)
{
	//access the array based on the count Cnt
}
int main()
{


	Student *student[3];
	student[0] = new Student();	
	student[1] = new Student();	
	student[2] = new Student();	

	ProcessStudent(student,3);
}


Best Regards
Muthuraja
   
Comments
BrianHamilton 16-Feb-13 13:03pm
   
void ProcessStudent(Student stu[], int Cnt) as opposed to void ProcessStudent(Student * stu[], int Cnt)but other than that, works fine. Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900