C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 12-31-2008, 07:09 AM   #1
Registered User
 
Join Date: Dec 2008
Posts: 7
calling struct class within array

Hello

i have a problem calling the struct class data from inside an array...
error: C2664: 'DrukStudent' : cannot convert parameter 1 from 'int' to 'student'.

Code:
struct student
{
	char naam[25];
	struct datum gebdatum;
	int resultaat;
};

void DrukStudent(struct student s)
{	/* naam en gebdatum (dd/mm/jjjj) afdrukken */
	printf("%-10s",s.naam); 
	DrukDatum(s.gebdatum);
	printf(" %d%%",s.resultaat);
}

double gemiddelde(struct student studentrij[ ], int aantal)
{
	int i;
	double result=0.0;
	printf("\ntest array\n");
	DrukStudent(studentrij[1].resultaat); /* here is the problem */
	return result;
}

void main()
{
	struct student studentrij[20] = {{"Anton",{25,4,1988}, 75},{"Bert",{24,5,1987}, 85},{"Chris",{23,6,1986}, 95},{"Dave",{22,7,1985}, 100}};
	gemiddelde(studentrij,4);
}
My purpose is to calculate with the int resultaat within all these arrays.
And i cant seem to target them.

I do not wish to use any pointers (!!)

I know that my double gemiddelde(struct student studentrij[ ], int aantal) isnt looking like it is supposed to be, but right now i just want to target the class of resultaat and then i can move on.



Thanks and happy new year
eastmus is offline   Reply With Quote
Old 12-31-2008, 07:12 AM   #2
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,099
DrukStudent expects a Student struct, but you pass an int.
And main shall return int, always.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 12-31-2008, 07:29 AM   #3
Registered User
 
Join Date: Dec 2008
Posts: 7
thanks Elysia, but i cant seem to figure out how to target 85 only.
since

Code:
DrukStudent(studentrij[1]);
will give

Code:
Bert      24/05/1987       85%
I dont need the name and date , but just the last int.
eastmus is offline   Reply With Quote
Old 12-31-2008, 07:32 AM   #4
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,099
So why are you printing the name and the date inside the function?
Remove those printfs, change the function to take the score only and then just print the score.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 12-31-2008, 07:42 AM   #5
Registered User
 
Join Date: Dec 2008
Posts: 7
Quote:
Originally Posted by Elysia View Post
So why are you printing the name and the date inside the function?
Remove those printfs, change the function to take the score only and then just print the score.
it would work then with

Code:
void DrukStudentGemiddelde(struct student s)
{	/* naam en gebdatum (dd/mm/jjjj) afdrukken */
	printf(" %d",s.resultaat);
}
but my point of learning to use struct was trying to target the score by calling it, without making new functions and structs or arrays etc ...

if there is rly no other way ....
eastmus is offline   Reply With Quote
Old 12-31-2008, 07:51 AM   #6
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,740
Except what you have is targeting the score by calling it, without any extra structs or arrays. How is it not what you want?
tabstop is offline   Reply With Quote
Old 12-31-2008, 08:23 AM   #7
Registered User
 
Join Date: Sep 2006
Posts: 2,508
If I understand this correctly, I'd use a while loop to move the index array from 20(minus 1, so 19 really), back to the comma. The first number would be your one's column digit, so no problem. Your second number, if present, would need to be X 10 + one's column digit, for your total number.

Or, another way, just let the index decrement back to the comma, then reverse it and read in the digits. If you read in 3 digits, you'll need to do this:

Correct value = digit1 * 100 + digit2 * 10 + digit3

to get the value right.

Code:
i = 19;
while(structArray[i] != ',')  //moving index back to the comma
   --i;

for(j = 0; i < 20; i++)   {
   if(structArray[i] >= 0 && structArray[i] <= 9)  {  
      numberchar[j++] = structArray[i];
   }
}

for(i = j - 1; i < MaxChars (2 or 3); i++)   {
   temp = numberchar + '0';  //elevate char to a number
   if(i = 3)                 //restore it's 10's place, again.
      sum = temp * 100;
   else if(i = 2)
      sum += temp * 10;
   else
      sum += temp;
}
print your sum!

I'm assuming 3 or fewer digits in this sample, and have not run this. It would be my starting place, however.
Adak is offline   Reply With Quote
Reply

Tags
array, struct

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with linked list sorting function Jaggid1x C Programming 6 06-02-2009 02:14 AM
deriving classes l2u C++ Programming 12 01-15-2007 05:01 PM
Array of struct pointers - Losing my mind drucillica C Programming 5 11-12-2005 11:50 PM
Dikumud maxorator C++ Programming 1 10-01-2005 06:39 AM
struct nested in a class - member variables initialization Viana C++ Programming 4 12-12-2002 02:32 PM


All times are GMT -6. The time now is 01:39 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22