l********y 发帖数: 1327 | 1 how to copy a string without using strcpy function in only one clause? for
example
char * str1 = "welcome";//this is source to be copied
//want to copy str1 to dest using only one clause!
......char * dest ......//how to write this clause? |
c********0 发帖数: 112 | 2 while( *a++ = *b++) 可以吗
这种问题啥意义啊 |
c********1 发帖数: 161 | 3 while((dest[i++] = src[i++])!= '\0');
Is that OK? |
l********y 发帖数: 1327 | 4 i think this is ok but how do you allocate memory for dest * ?
i know in some compiler it will work like mine, but still dest * is not
allocated any memory.
【在 c********1 的大作中提到】![](/moin_static193/solenoid/img/up.png) : while((dest[i++] = src[i++])!= '\0'); : Is that OK?
|
l********y 发帖数: 1327 | 5 no yiyi, only to screen ppl and find the geekest geek.
and how do u pronounce geek? [geik] or [d3ik] ?
【在 c********0 的大作中提到】![](/moin_static193/solenoid/img/up.png) : while( *a++ = *b++) 可以吗 : 这种问题啥意义啊
|
l*****g 发帖数: 685 | 6 strcpy不行,strncpy,memcpy行不行?
【在 l********y 的大作中提到】![](/moin_static193/solenoid/img/up.png) : how to copy a string without using strcpy function in only one clause? for : example : char * str1 = "welcome";//this is source to be copied : //want to copy str1 to dest using only one clause! : ......char * dest ......//how to write this clause?
|
e*****e 发帖数: 1275 | 7 你应该这么问,
只许用一句instruction....听好喽。。。系instruction 哦。。。。C code, java 啥
的不算~~~
前面那个coconut001滴答案,compile出来好多好多instruction,大大的不行。
重新设计一个CPU,专门定义一个instruction,就干这个 |
r********g 发帖数: 1351 | 8 是string还是character array呢?如果character array很难吧,分配空间至少算一句
了。。。
【在 l********y 的大作中提到】![](/moin_static193/solenoid/img/up.png) : how to copy a string without using strcpy function in only one clause? for : example : char * str1 = "welcome";//this is source to be copied : //want to copy str1 to dest using only one clause! : ......char * dest ......//how to write this clause?
|
n*******r 发帖数: 22 | 9 It's not pretty, but works :)
char* dest = const_cast( (new string(str1))->c_str() );
for
【在 l********y 的大作中提到】![](/moin_static193/solenoid/img/up.png) : how to copy a string without using strcpy function in only one clause? for : example : char * str1 = "welcome";//this is source to be copied : //want to copy str1 to dest using only one clause! : ......char * dest ......//how to write this clause?
|
l********y 发帖数: 1327 | 10 这个好,很难想出来啊
【在 n*******r 的大作中提到】![](/moin_static193/solenoid/img/up.png) : It's not pretty, but works :) : char* dest = const_cast( (new string(str1))->c_str() ); : : for
|
c*********t 发帖数: 32 | 11 但是这个没有内存泄漏问题吗?
下面这么用似乎跟安全,不过没法用一行来写
auto_ptr src(new string(str));
char * dest = const_cast(src->c_str());
【在 n*******r 的大作中提到】![](/moin_static193/solenoid/img/up.png) : It's not pretty, but works :) : char* dest = const_cast( (new string(str1))->c_str() ); : : for
|