将DEFINE翻译成char * [英] Translating a DEFINE to char*
问题描述
亲爱的人,
以下代码正在编译:
#define BUF_SZ 16383
.. ...
strcat(ConnectString,Content-Length:BUF_SZ \ n);
但它不起作用,因为它给了我:
内容长度:BUF_SZ而不是
内容长度:16838
有办法处理这个?我想要的是在字符串中使用
中的缓冲区,但也要保持简单,并保持其灵活性。
Dear people,
The code below is compiling:
#define BUF_SZ 16383
.....
strcat(ConnectString, "Content-Length: BUF_SZ\n");
but it does not work since it give me:
Content-Length: BUF_SZ and not
Content-Length: 16838
Is there a way to handle this? What I want is to get buffersize used in
the string, but also somehow keep it simple, and keep it flexible.
推荐答案
ma*********@hotmail.com < ma*********@hotmail.com>写道:
ma*********@hotmail.com <ma*********@hotmail.com> wrote:
#define BUF_SZ 16383
....
strcat(ConnectString," Content-Length:BUF_SZ \ n");
>但它不起作用,因为它给了我:
内容长度:BUF_SZ而不是
内容长度:16838
有没有办法处理这个?我想要的是在字符串中使用缓冲区,但也保持简单,并保持灵活。
#define BUF_SZ 16383
....
strcat(ConnectString, "Content-Length: BUF_SZ\n");
but it does not work since it give me:
Content-Length: BUF_SZ and not
Content-Length: 16838
Is there a way to handle this? What I want is to get buffersize used in
the string, but also somehow keep it simple, and keep it flexible.
尝试snprintf(),simpe并且灵活。
-
:wq
^ X ^ Cy ^ K ^ X ^ C ^ C ^ C ^ C >
ma ********* @ hotmail.com 写道:
亲爱的人们,
下面的代码正在编译:
#define BUF_SZ 16383
....
strcat(ConnectString,Content-Length:BUF_SZ \ n);
但它不起作用,因为它给了我:
内容长度:BUF_SZ而不是
内容长度:16838
有没有办法处理这个?我想要的是在字符串中使用缓冲区,但也保持简单,并保持灵活。
Dear people,
The code below is compiling:
#define BUF_SZ 16383
....
strcat(ConnectString, "Content-Length: BUF_SZ\n");
but it does not work since it give me:
Content-Length: BUF_SZ and not
Content-Length: 16838
Is there a way to handle this? What I want is to get buffersize used in
the string, but also somehow keep it simple, and keep it flexible.
宏不在字符串中替换或者在评论中。你可以用这样的sprintf实现你想要的东西:
char my_string [BIG_ENOUGH];
sprintf (my_string," Content-Length:%d \ nn",BUF_SZ);
HTH
Macros are not substituted inside strings or inside comments. You can
achieve what you want using sprintf like this:
char my_string[BIG_ENOUGH];
sprintf(my_string, "Content-Length: %d\n", BUF_SZ);
HTH
óú星期四,2006年1月5日00:38:32 -0800?ma*********@hotmail.comD'μ?>
óú Thu, 05 Jan 2006 00:38:32 -0800£?ma*********@hotmail.comD′μ?£o
亲爱的人们,
下面的代码是编译:
#define BUF_SZ 16383
....
strcat(ConnectString," Content-Length:BUF_SZ \\ \
");
sprintf(" ConnectString," Content-Length:%d \ n",BUF_SZ);
/ *
%d - int
%u - unsigned int
%s - char *
%c - char
.. ..
* /
但它不起作用,因为它给了我:
内容长度:BUF_SZ而不是
内容-Length:16838
有办法解决这个问题吗?我想要的是在字符串中使用缓冲区,但也要保持简单,并保持灵活。
Dear people,
The code below is compiling:
#define BUF_SZ 16383
....
strcat(ConnectString, "Content-Length: BUF_SZ\n"); sprintf("ConnectString, "Content-Length: %d\n",BUF_SZ);
/*
%d -- int
%u -- unsigned int
%s -- char *
%c -- char
....
*/
but it does not work since it give me:
Content-Length: BUF_SZ and not
Content-Length: 16838
Is there a way to handle this? What I want is to get buffersize used in
the string, but also somehow keep it simple, and keep it flexible.
这篇关于将DEFINE翻译成char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!