Help with function declaration

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Help with function declaration

 
0
  #1
Mar 17th, 2008
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
  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!
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,679
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: Help with function declaration

 
0
  #2
Mar 17th, 2008
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:
  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. }
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Re: Help with function declaration

 
0
  #3
Mar 17th, 2008
Thanks! I guess I should have been able to figure that out!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC