15,979
社区成员
发帖
与我相关
我的任务
分享
char* _stdcall stringCombo(char* str1, char* str2)
{
char* str3= "upstring=";
char* str4 = "&upFullFileName=";
int L=0;
char combo=new char[1024]; //使用一个大点的缓冲区,以确保够用
char* px=combo;
L=strlen(str3);
memcpy(px,str3,L);
px+=L;
L=strlen(str1);
memcpy(px,str1,L);
px[L]=";";//分隔一下
px++;
L=strlen(str4);
memcpy(px,str4,L);
px+=L;
L=strlen(str2);
memcpy(px,str2,L);
px[L]=0;
return combo
}
CString _stdcall stringCombo(CString* str1, CString* str2)
{
CString str3= "upstring=";
CString str4 = "&upFullFileName=";
CString combo = str3+ str1+ str4+ str2;
return combo;
}
char* _stdcall stringCombo(char* str1, char* str2)
{
char* str3 = "upstring=";
char* str4 = "&upFullFileName=";
int nLen = strlen(str3);
nLen += strlen(str4);
if (str1)
nLen += strlen(str1);
if (str2)
nLen += strlen(str2);
char* combo = new char[nLen + 1];
if (combo)
{
memset(combo, 0, nLen + 1);
sprintf_s(combo, nLen + 1, "%s%s%s%s", str3, str1, str4, str2);
}
return combo;
}
int main()
{
char* pRetChar = stringCombo("hello", "word");
if (pRetChar)
{
printf_s(pRetChar);
delete[] pRetChar;
}
return 0;
}
[/quote]兄弟666
char* _stdcall stringCombo(char* str1, char* str2)
{
char* str3 = "upstring=";
char* str4 = "&upFullFileName=";
int nLen = strlen(str3);
nLen += strlen(str4);
if (str1)
nLen += strlen(str1);
if (str2)
nLen += strlen(str2);
char* combo = new char[nLen + 1];
if (combo)
{
memset(combo, 0, nLen + 1);
sprintf_s(combo, nLen + 1, "%s%s%s%s", str3, str1, str4, str2);
}
return combo;
}
int main()
{
char* pRetChar = stringCombo("hello", "word");
if (pRetChar)
{
printf_s(pRetChar);
delete[] pRetChar;
}
return 0;
}