View Single Post
  #12   Spotlight this post!  
Unread 01-11-2005, 03:41
BorisTheBlade's Avatar
BorisTheBlade BorisTheBlade is offline
lead programmer 2004
AKA: Dane
FRC #1351 (TKO)
Team Role: Mentor
 
Join Date: Oct 2005
Rookie Year: 2004
Location: San Jose, Ca
Posts: 23
BorisTheBlade has a spectacular aura aboutBorisTheBlade has a spectacular aura aboutBorisTheBlade has a spectacular aura about
Send a message via AIM to BorisTheBlade
Re: Typedef Struct as function input

Quote:
Originally Posted by Mike
I've never used pointers before really, so could you show an example?
here is a very simple example of pointers for you Mike

Code:
#include <stdio.h>

int modifyVariables(int *pB, char *pC, float *pD);

int main()
{
int a;
int b;
char c;
float d;

a = modifyVariables(&b, &c, &d);

printf("%d\n", a); //prints 7
printf("%d\n", b); //prints 6
printf("%c\n", c); //prints g
printf("%2.1f\n", d); //prints 22.1
return 0;
}

int modifyVariables(int *pB, char *pC, float *pD)
{
*pB = 6; //sets int b in main function to 6
*pC = 'g'; //sets char c in main function to g
*pD = 22.1; //sets float d in main function to 22.1
return 7;
}
you can only return one variable from a function how ever by sending pointers to variables you can modify more than one variable without returning the values in a return statement.
__________________
Team 1351 TKO Robotics (click for our website)
2007 sacramento regional Johnson & Johnson Sportsmanship Award winners
2007 CAL Games Finalists