c++ - How to add strings? -
i'm new c++ , i'm making simple program
tchar config_name[32]; tchar config_processname[32]; int = getprivateprofilestring("injection", "name", "", config_dllname, 32, path); but need add char* it, because needs full path. example, it's doing just
mydll.dll
but needs doing
c:/folder/anotherfolder/mydog/mydll.dll
i tried doing
char* dllloc = "null"; sprintf(dllloc, "%s%s", dir, config_dllname); but crashes
the problem dllloc hasn't had sufficient space allocated accommodate string concatenation.
a solution pre-allocate large char buffer , use instead, below.
#define config_dllname "configdllname" int main() { char str[1024]; const char* dir = "dir"; sprintf(str, "%s%s", dir, config_dllname); printf(str); } if strings exceeds 1024 characters, you'll run same problem; welcome string operations in c. :)
also, since marked c++ question, there reason you're not using std::string? make life easier.
Comments
Post a Comment