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 429,896 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,452 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: 746 | Replies: 4
Join Date: Sep 2007
Posts: 17
Reputation: BigFormat is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
BigFormat BigFormat is offline Offline
Newbie Poster

Pass a string by reference

  #1  
May 8th, 2008
I have to pass a string to a function that strcats something to it, in K&R I read to pass a pointer to it, but I don't know where to allocate buffer...
Is there a difference betw passing an empty string or not?
My printf starts with some strange symbols, and then the string...

  1. int main() {
  2.  
  3. char *string;
  4.  
  5. //here or in string_concat? or both?
  6. string = (char*) malloc(16 * sizeof(char));
  7.  
  8. string_concat( &string );
  9.  
  10. printf("%s", string);
  11.  
  12. return 0;
  13. }
  14.  
  15.  
  16. void string_concat( char **string ) {
  17.  
  18. //write in string something, need a realloc?
  19. strcat(*string, something);
  20.  
  21. }
AddThis Social Bookmark Button
Reply With Quote  

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 9:03 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC