User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 402,096 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,511 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 372 | Replies: 2 | Solved
Reply
Join Date: Oct 2004
Location: San Francisco, CA
Posts: 338
Reputation: paradox814 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 2
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Help with function declaration

  #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
int intToHexStr(char *, unsigned int)
{
  //how do I reference the first argument?
  //and how do I reference the second argument?
}

Please help, thanks in advance!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2007
Location: South Dakota
Posts: 773
Reputation: vmanes is a jewel in the rough vmanes is a jewel in the rough vmanes is a jewel in the rough 
Rep Power: 5
Solved Threads: 78
vmanes's Avatar
vmanes vmanes is offline Offline
Master Poster

Re: Help with function declaration

  #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. }
Drunk driving deaths were reported to be down in 32 states in 2007. Apparently the other 18 states are still prosperous enough where people still can afford to pay for gasoline.
Reply With Quote  
Join Date: Oct 2004
Location: San Francisco, CA
Posts: 338
Reputation: paradox814 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 2
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Re: Help with function declaration

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

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 1:51 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC