Click here to Skip to main content
12,243,522 members (48,383 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++ C
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 16-Feb-13 7:12am
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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

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
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160426.1 | Last Updated 16 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100