-
just a fuction problem
How can i make "Display" fuction work?
thanks
Code:
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
//********* prototype******//
void Display();
struct info
{
int test;
};
//*********M a i n **********/
void main()
{
struct info inf;
printf("Enter number :");
scanf("%d",&inf.test);
Display(inf.test);
//printf("\n show: %d",inf.test);
}
//*******Function**************//
void Display()
{
struct info in;
printf("\n show: %d",in.test);
}
Thanks
-
It should be int main () instead of void main (). You forget to pass the structure to the function. Didn't your compiler give a warning/error about it?
Code:
void Display (struct info in);
int main (void)
{
...
Display (in);
return 0;
}
void Display (struct info in)
{
printf("\n show: %d",in.test);
}
-
> Didn't your compiler give a warning/error about it?
Probably not
It may have looked like a prototype, but it isn't really. It's just an old-style forward declaration.
void Display();
really means in C
void Display(...);
So all you can tell from this is that Display is a function - and that's it. You can pass any number of any parameters to it, and the compiler will say absolutely nothing about the correctness (or lack of).