943,948 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 2958
  • C++ RSS
Mar 17th, 2008
0

Help with function declaration

Expand Post »
I am working with a function declaration of:
int func1(char *, unsigned int)

to the best of my understanding, I am not allowed to modify this. Now my question is that when I actually write this program what is the name of argument 1 and 2

for example
C++ Syntax (Toggle Plain Text)
  1. int intToHexStr(char *, unsigned int)
  2. {
  3. //how do I reference the first argument?
  4. //and how do I reference the second argument?
  5. }

Please help, thanks in advance!
Similar Threads
Reputation Points: 13
Solved Threads: 4
Posting Whiz
paradox814 is offline Offline
351 posts
since Oct 2004
Mar 17th, 2008
0

Re: Help with function declaration

What you've been given is the function prototype, which describes to the compiler the "signature" of the function. When you write your implementation (definition) of it, you must supply parameter names for the function to use. So in your program, it might look like:
c++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int func1(char *, unsigned int); //prototype, note the semicolon at end
  5.  
  6. int main( )
  7. {
  8. char str[256] = "";
  9. int num = 3;
  10. int ret_val = 0;
  11.  
  12. ret_val = func1( str, num );
  13.  
  14. return 0;
  15. }
  16.  
  17. int func1(char * foo, unsigned int bar) //parameter names here
  18. {
  19. strcpy( foo, "hello" );
  20. for( int i = 0; i < bar; i++ )
  21. strcat( foo, " world" );
  22. return strlen( foo );
  23. }
Reputation Points: 1268
Solved Threads: 228
Posting Virtuoso
vmanes is offline Offline
1,895 posts
since Aug 2007
Mar 17th, 2008
0

Re: Help with function declaration

Thanks! I guess I should have been able to figure that out!
Reputation Points: 13
Solved Threads: 4
Posting Whiz
paradox814 is offline Offline
351 posts
since Oct 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: How to link an MFC form to source code?
Next Thread in C++ Forum Timeline: More on my first uni assignment





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC