Code:#include<stdio.h> const a * z =Null struct { }z; int init_test (const a *b) { z=b; } int main(void){ { init_test(1) return0;}
- I want to call init function through main i dont understand why any one can explain how to od this?
Code:#include<stdio.h> const a * z =Null struct { }z; int init_test (const a *b) { z=b; } int main(void){ { init_test(1) return0;}
- I want to call init function through main i dont understand why any one can explain how to od this?
Last edited by amahmoo; 11-22-2015 at 12:27 PM.
Please post your code in [code][/code] bbcode tags without any extra markup. Your code has unnecessary bbcode tags strewn all over, and I'm feeling too lazy to remove them for you.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
sorry about that i just fixed it
What is init_test supposed to do?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Um, I suggest that you go back to your learning material about how to declare struct types and define objects of struct types.
Here are my specific comments:
What is a? It is not declared anywhere. Null is wrong. You probably intended NULL. Furthermore, you appear to be trying to declare a global variable named z. Generally, global variables should be avoided.Code:const a * z =Null Why does the struct type have no members, and why did you declare an object of the struct type with the name z when you apparently wanted to declare a pointer named z just before that?Code:struct { }z; Why do you pass 1 to init_test?Code:init_test(1)
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Um, I suggest that you go back to your learning material about how to declare struct types and define objects of struct types.
Here are my specific comments:
What is a? It is not declared anywhere. Null is wrong. You probably intended NULL. Furthermore, you appear to be trying to declare a global variable named z. Generally, global variables should be avoided.Code:const a * z =Null
I know this your right Why does the struct type have no members, and why did you declare an object of the struct type with the name z when you apparently wanted to declare a pointer named z just before that?Code:struct { }z;
It has no members because im using it as a example Why do you pass 1 to init_test?Code:init_test(1)
I dont know what to pass through init_test to call it this is where my question is
Also the struct is in a head file
the anwsers are in qoutations
Well, this is a chicken and egg scenario: what members does the struct have? Presumably you would pass in values to be used to initialise the struct. For example:Originally Posted by amahmoo
Code:#include<stdio.h> struct X { int n; }; void X_init(struct X *x, int n) { x->n = n; } int main(void) { struct X obj; X_init(&obj, 123); printf("%d\n", obj.n); return 0; }
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
The struct has function prototypes and its in a headfile
Thank you so much for ur help I really needed guidance you hae no idea thnk you
Code:#includeCode:<stdio.h> struct found in header file struct { (functionprototypes) }z; int init_test (const a *b) { z=b; } const a * z =Null int main(void){ { init_test(1) return0;}
this is what it has in struct
Huh? Please be careful when posting code. Your code makes no sense whatsoever. It would help if you stopped replacing code with English sentences.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
func1 return 1 and func 2 return 0 onlyCode:bool_t func( Di* re ) { bool_t response = true; if ( re->inst > maxinstant ) { re->errCode = this_is_ error_code; } else if ( re->inst == 0 ) { response = func1( req ); } else { Response = func2( req ); } return ( response); }
How would i call in main? func?
When you say "func?", are you asking if this is a way to call the function?Originally Posted by amahmoo
If so, you really need to revise what you should know by now about function calls. You are asking a question to which there can be a multitude of plausible answers. For example:Code:func
Code:Di x; func(&x);
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Goodness, where did this code come from?
You don't need to identify or call functions with "func" (as it seems perhaps you believe?)
If you are having trouble understanding function calls, you really need to learn about it, and then try a simple example. Leave out the pointers and all that. If you can't get that to work, post it!