-
Problem with structures
I wrote this program but it does not return the information i want it excutes fine but it does not return what i want it to.
Code:
#include <stdio.h>
typedef struct{
int number;
int place;
int postcode;
} information_t;
int test(information_t *in);
int main()
{
information_t information;
information_t *in;
printf(" Please enter the number: ");
scanf(" %d",&information.number);
printf(" Please enter the place: ");
scanf(" %d",&information.place);
printf(" please enter the postcode: ");
scanf(" %d",&information.postcode);
test(in);
return 0;
}
int test(information_t *in)
{
int position;
position= printf(" The number is %d the place is %d and the postcode is %d\n", &in->number, &in->place, &in->postcode);
//printf(" The number is %d the place is %d and the postcode is %d\n", &in->number, &in->place, &in->postcode);
return(position);
}
-
So how about actually asking a smart question? What do you expect it to do? What does it do that it shouldn't? What doesn't it do that it should? Sample input / output?
Quzah.
-
Details
the code is meant to ask the user for 3 inputs number,place(in form of numbers) and a postcode
here is what it should look like
Please enter the number: 10
Please enter the place: 10
please enter the postcode: 10
The number is 10 the place is 10 and the postcode is 10
but here is what it looks like
Please enter the number: 10
Please enter the place: 10
please enter the postcode: 10
The number is 1324234 the place is 1324238 and the postcode is 1324242
Press any key to continue...
-
You are passing a pointer (in) to the test function, you haven't done anything with this pointer, it's uninitialised.
-
The "other" problem though, is that you're printing the address of all your variables, not their values.
Lose the &.
Quzah.
-
That too, I didn't even look inside the function.
That would explain the suprising lack of crash from the original code.