Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

programering

char* linker

This topic is 5650 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have tried to link together three strings(char *), but it didn''t work when I wrote like this: char *path = "path/"; char *name = "file"; char *format = ".dat"; char *adress; adress = path + name + format; // or when I did like this: #define STRING_LINKER(a,b,c) ((a) ## (b) ## (c)) adress = STRING_LINKER(path,name,format); How shall I do it, is there any function that handles this? Anton Karlsson Klingis Entertainment Games with silly humor

Share this post


Link to post
Share on other sites
Advertisement
The c way would use sprintf or strcat.
  char *path = "path/";
char *name = "file";
char *format = ".dat";
char *address = (char*)malloc(strlen(path) + strlen(name) + strlen(format) + 1);
sprintf(address, "%s%s%s", path, name, format);

// do stuff with address


free(address);
With c++-style strings, the code becomes:
  
#include <string>

using std::string;


string path = "path/";
string name = "file";
string format = ".dat";
string address = path + name + format;
...I tend to prefer the latter.

[edited by - Beer Hunter on April 1, 2003 6:16:40 AM]

Share this post


Link to post
Share on other sites
strcat

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_strcat.2c_.wcscat.2c_._mbscat.asp

strcpy

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_strcpy.2c_.wcscpy.2c_._mbscpy.asp

Goolge

www.Goolge.com

[edited by - Drazgal on April 1, 2003 6:50:20 AM]

Share this post


Link to post
Share on other sites
Like this then?
Correct me if I''m wrong here.

char *path = "path/";
char *name = "file";
char *format = ".dat";

char *adress;
adress = (char *)
malloc(sizeof(path) + sizeof(name) + sizeof(format));

strcpy(adress,path);
strcat(adress,name);
strcat(adress,format);


What does strcat stands for short?




Anton Karlsson
Klingis Entertainment
Games with silly humor

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!