help with passing the right parameter

Ok so I have a function definition like this:

int betterRunner(const Trunner *runner1, const Trunner *runner2);

in main I have something like this

Trunner = runner1, runner2;

betterRunner(runner1, runner2);

...

and get a error:
expected 'const struct Trunner *' but argument is of type 'Trunner'
if I use the address of opperater & then it seems to work but some of the data when printed comes out all jacked up.

The question is how do I pass the runner to the function so the data inside does not come out as garbage?

Thanks
Jason
Last edited on
Can we see how betterRunner is implemented.

Also can we see what the members of Trunner look like? Sounds to me like things aren't being initialized.
sure here is Runner.h

#include "time.h"

// Trunner strct
typedef struct
{
char name[20];
Ttime time;

}Trunner;

//Function definitions for Trunner struct
void readName(Trunner *runner, const char *prompt);
void readTime(Trunner *runner, const char *prompt);
void displayRunner(const Trunner *runner);
int betterRunner(const Trunner *runner1, const Trunner *runner2);

and here is the implamentation runner.c

#include <stdio.h>
#include <string.h>
#include "Runner.h"

void readName(Trunner *runner, const char *prompt)
{
char name[20];
printf("\n%s", prompt);
scanf("%s", name);
strcpy(runner->name, name);

}

void readTime(Trunner *runner, const char *prompt)
{
read_time(&runner->time, "Enter runners time. (hh mm)");
debug_print_time(runner->time);
}

void displayRunner(const Trunner *runner)
{
printf("Name \t\t Time\n\n");
printf("%s", runner->name);
printf("\t\t");
print_time(runner->time, -1);
debug_print_time(runner->time);
printf("\n");
}

int betterRunner(const Trunner *runner1, const Trunner *runner2)
{
int ret;

ret = compare_times(runner1->time, runner2->time);

if(ret == 1)
{
return 1;
}
else
{
return 2;
}

}

the compare time function it Ttime is like this
int compare_times(Ttime t1, Ttime t2)
{
if(t1.min < t2.min)
{
return -1;
}
if(t1.min > t2.min)
{
return 1;
}
if(t1.min == t2.min)
{
return 0;
}
return 0;
}

main looks like this

#include <stdio.h>
#include "Runner.h"

int main()
{
Trunner runner1, runner2;
int ret;

readName(&runner1, "Give the name for the runner 1? ");
readName(&runner2, "Give the name for the runner 2? ");

readTime(&runner1, "Give the time for the runner 1? ");
readTime(&runner1, "Give the time for the runner 1? ");

ret = betterRunner(runner1, runner2);

printf("ret is %d", ret);
if(ret == 1)
{
displayRunner(&runner1);
}

else
{
displayRunner(&runner2);
}

return 0;
}

when it displays the time in the end its some huge # when I pass using &runner.
Last edited on
It looks to me that your betterRunner function is expecting two pointers, however, you're passing in two static instances of the Trunner class.
ok well then pointers still seem to have me confused. What do I need to pass then to make this right? I tried just runner1 and *runner1 both complain about invalid conversions and dont work. the &runner1 seems to run but is not what it is looking for. Suggestions anyone?
Post your code in code block. [ code][/code ] removing the leading and trailing space in the tags I just gave you. Post your error and the line number the error is occurring in the code you post.
Topic archived. No new replies allowed.