Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

functions & arrays 1

Status
Not open for further replies.

XoFF

Programmer
Jun 22, 2003
23
GB
hi,

i wanna use an array in my main for declaring and fill the array.

but i wanna use in my function the array to determine who is oldest person

but when i call my function in main i get error :
parse error before ']' token

here is code:

#include <stdio.h>

int oldest(int array [2][3])
{
int i,j,pers;
for(j=0;j<3;j++){
if (array[0][j]==array[1][j])
if (j==2)
pers=0;
else if(array[0][j]>array[1][j]){
pers=1;
break;
}else{
pers=2;
break;
}
}
}

main()
{
int array[2][3],i,j;
for(i=0;i<2;i++){
for(j=0;j<3;j++){
printf(&quot;year of birth - persoon %d: &quot;,i+1);
scanf(&quot;%d&quot;,&array[j]);
printf(&quot;month of birth - persoon %d: &quot;,i+1);
scanf(&quot;%d&quot;,&array[j]);
printf(&quot;day of birth - persoon %d: &quot;,i+1);
scanf(&quot;%d&quot;,&array[j]);
}
printf(&quot;\n&quot;);
}
printf(&quot;Oldest person: %d&quot;,oldest(array[][])); /*->parse error before ']' token*/
}

 
1. When posting code, please use the [ code ][ /code ] tags to preserve the formatting (and content of your code). If you notice, all your
Code:
[i]
subscripts have turned the rest of your code into italics.

2. The way you pass an array to a function is just to use the name of the array, so
Code:
printf(&quot;Oldest person: %d&quot;,oldest(array) );
 
sorry for that

yes i found the error but thx anyway.

in function :

Code:
int oldest person(ar)
int ar[][3]
{
	blabla
}
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top