C语言经典笔试题

时间:2022-06-01 21:37:30
写C语言的拷贝函数,要求复制字符串,并且将复制后的字符串逆序 比如from中是1234,  则to中是4321 void  strcyp(char * to,const char * from)问题补充:   
要求: 不能使用库函数 不能定义其他的变量。

193 个解决方案

#1


没有人看吗,想了一下午都没想出来,求高手指教哇!请注意要求!!

#2


from++到‘\0’ - 1处,赋值给to,to就指向逆序的from了

#3


引用 2 楼 c_helloworld 的回复:
from++到‘\0’ - 1处,赋值给to,to就指向逆序的from了

呵呵,不做评论

#4


求给出代码啊

#5


[code=c/c++]
void strCpy(char *to,const char * from)
{
while(*from)
{
from++;
}
from--;
while (*from)
{
to[0]=*from;
to++;
from--;
}
to[0]='\0';
}
[\code]

#6


递归?

#7



void strCpy(char *to,const char * from)
{
while(*from)
{
from++;
}
from--;
while (*from)
{
to[0]=*from;
to++;
from--;
}
to[0]='\0';
}

#8


[code=c/c++] 
void strCpy(char *to,const char * from) 

while(*from) 

from++; 

from--; 
while (*from) 

to[0]=*from; 
to++; 
from--; 

to[0]='\0'; 

[code]

#9


void Ch_cpy(char a[],int n)
{
char temp;
int i,j;
int m=n/2;
for(i=0;i<m;i++)
{j=n-1-i;
temp=a[i];a[i]=a[j];a[j]=temp;
}
return;
}
main()
{
int i;
char a[11]={"helloworld!"};
for(i=0;i<10;i++)
printf("%c",a[i]);
printf("\n");
Ch_cpy(a,10);
for(i=0;i<10;i++)
printf("%c",a[i]);
printf("!");
system("pause");

}

我也是初学着,不过程序可用.

#10


不能使用其他的变量?也就是只有from和to?

#11


第二个while(*from)是什么意思呢?

#12


引用 10 楼 wjl19890711 的回复:
不能使用其他的变量?也就是只有from和to?

Yes!

#13


引用 11 楼 betamark 的回复:
第二个while(*from)是什么意思呢?

第一个到尾巴上
第二个再头上顺便给to赋值

#14



void strcyp(char * to,const char * from)
{
ASSERT(to);
ASSERT(from);
while(from!=NULL)
{
 *to = *from;
     to++;from++;
}
*to = '\0';
}

#15


C语言经典笔试题?

#16


#include<iostream>
using namespace std;
char * rstrcpy(char *to,const char*from)
{
to=to+3;
for(int i=0;i!=4;i++)
{
*(to-i)=*(from+i);
}
*(to+1)='\0';

return to;
}
int main()
{
const char *from="1234";
    char *to;
to=(char *)malloc(sizeof(char)*5);;
rstrcpy(to,from);
cout<<to<<endl;
    return 0;
}

#17


引用 15 楼 udbwcso 的回复:
C语言经典笔试题?

难道这个还不经典?

#18


5楼,高手……

#19


#include <locale>
#include <iostream>
using namespace std;


void rstrcpy(char *from,char *to)
{
  int i= strlen(from)-1;
  while(i>=0)
  {
    *to=from[i];
to++;
i--;
  } 
}

int main( )   
{
   char t[5]="0000";
//for(int i = 0;i<16;i++ )
   char s[5]="1234";
   rstrcpy(s,t);
   printf("%s",t);
}

#20


感觉应该用递归,能力有限。。

#21


经典啊!

#22


引用 19 楼 wcg_jishuo 的回复:
#include <locale>
#include <iostream>
using namespace std;


void rstrcpy(char *from,char *to)
{
  int i= strlen(from)-1;
  while(i>=0)
  {
    *to=from[i];
to++;
i--;
  } 
}

int mai……

你用了strlen函数

#23


#include<stdio.h>
void Strcpy(char* to, const char *from) {
*to = '\0';
while (*from != '\0')
*(++to) = *(++from);
--to;
--from;
while (*to != '\0')
--to;
*to = *from;
while (*to != '\0') {
*(to++) = *(from--);
}
}

int main() {
char buf[4];
Strcpy(buf, "456789");
printf("buf=%s\n", buf);
return 0;
}
自己写的代码。为什么我去掉printf("buf=%s\n",buf);中的"\n"就什么都打印不出来呢,是缓冲区已满吗?

#24


#include <stdio.h>
#include <malloc.h>

void strcyp(char *to,const char *from);

main(){
   char *from = "hello,the world!" ;
   char *to ;
   strcyp(to,from);
   getch();
}

void strcyp(char *to,const char *from){
   int i = 0 ;
   char *to_ ;
   printf("%s\n",from);
   while(*from++!='\0'){
        i++ ;
   }
   from = from -2 ; /*在这里需要注意的是,while里的*from++,即使判断为‘\0’,让会执行++操作,不知道是不是winTC的缘故*/
   printf("%c \n",*from);
   printf("i=%d\n",i);
   to = (char *)malloc(sizeof(char)*i) ;
   to_ = to ; /*为to的开头*/
   while(i--){
      *to++ = *from-- ;1));
   }
   *to = '\0';
   printf("\n%s\n",to_);
}

#25



#include <stdio.h>
#include <malloc.h>

void strcyp(char *to,const char *from);

main(){
   char *from = "hello,the world!" ;
   char *to ;
   strcyp(to,from);

   getch();
}

void strcyp(char *to,const char *from){
   int i = 0 ;
   char *to_ ;
   printf("%s\n",from);
   while(*from++!='\0'){
        i++ ;
   }
   from = from -2 ;*在这里需要注意的是,while里的*from++,即使判断为‘\0’,让会执行++操作,不知道是不是winTC的缘故*/
   printf("%c \n",*from);
   printf("i=%d\n",i);
   to = (char *)malloc(sizeof(char)*i) ;
   to_ = to ;/*为to的开头*/
   while(i--){
      *to++ = *from-- ;1));
   }
   *to = '\0';
   printf("\n%s\n",to_);
}

#26


五楼不错

#27


引用 26 楼 hard1rock 的回复:
五楼不错

我也是这么认为的,呵呵

#28


递归的思路还是正确的,不知道这个成不

int do_strcyp( char* to, char* from )
{
if( *from == 0 )
{
return 0;
}
else
{
*(to + do_strcyp( to, from+1 )) = *from;
return do_strcyp( to, from+1 ) + 1;
}
}

void strcyp( char* to, char* from )
{
*(to + do_strcyp( to, from )) = 0;
}

#29


引用 21 楼 zichen0422 的回复:
经典啊!

int strlen(char *source, char target,int len)
{
int count = 0;
while(count!=len)
{
if (target ==*source ++)
break;
++count;
}
int count;
}

#30


此题出有的问题[写C语言的拷贝函数, 要求复制字符串,并且将复制后的字符串逆序 比如from中是1234, 则to中是4321]
如果不用库函数的话,如何复制字符串呢?也就是不申请内容,无法达到题要求.
5楼的,也没有考虑to指向的内存问题. 

#31



char *converse_copy(char *dest, const char *src)
{
    // 确定dest的首位置
    *dest = '\0';
    while (*src)
    {
        ++src;
        *(++dest) = ' ';
    }
    // 指向最后一个字符
    src--;
    // 确定dest的尾位置
    *dest = '\0';
    // 到首位置
    while (*--dest);
    *dest++ = *src--;
    while (*dest)
    {
        *dest++ = *src--;
    }
    src++;
    while (*src)
    {
        ++src;
        --dest;
    }
    return dest;
}

#32



        char * strcpy(char * strDest,const char * strSrc) 
        { 
             if ((strDest==NULL)||(strSrc==NULL)) //[1] 
                      throw "Invalid argument(s)"; //[2] 
             char * strDestCopy=strDest;    //[3] 
             while ((*strDest++=*strSrc++)!='\0'); //[4] 
             return strDestCopy; 
        } 



http://blog.csdn.net/hondely/article/details/6883155  
自己写了一点

#33


 

void strcopy(char *to,char *from)
{
  *to='\0';
  ++from;
  ++to;
  while(*from)
  {  
    *to=*from;
    from++;
    to++;
  }
    *to='\0';
     to--;
   while(*to!='\0')
   to--;
   from--;
   *to=*from;
   while(*to!='\0')
   {      
          *to=*from;
          to++;
          from--;   
   
   } 
  return;  
  
}
这个可以用,楼主试下

#34



#include<stdlib.h>
void change(char *to,const char * from)
{
*to='\0';
        while(*from!='\0')
        {
            from++;to++;
*to=*from;
        }
to--;*to='\0';to--;
        from--;

while(*to!='\0')
to--;

while(1)
{
*to=*from;

to++;from--;
if(*to=='\0')
{
*to=*from;
break;
}

}



}
int main(int argc,char *argv[])
{
char a[6];
char b[6];
memset(b,0,sizeof(b)); //初始化
strcpy(a,"12345"); //给a赋值a=12345
change(b,a); //倒序函数b=54321
printf("b=%s\n",b);
return 0;
}

花了1个小时写出来的,在linux下经过测试,b=54321

#35


如果不用递归实在是蛮简单的啊

#36


char* str_rev(const char* src,char* dst)
{
if(src == 0 || dst == 0)
return 0;

int i_len = 0; //作用是计算字符串长度
const char* temp = src;
for(;*src++ != 0;i_len++)
;
dst = dst+i_len;
while(*temp !=0)
*--dst= *temp++;
return dst;
}

#37


好,果然厉害
引用 5 楼 lsrongge 的回复:
[code=c/c++]
void strCpy(char *to,const char * from)
{
while(*from)
{
from++;
}
from--;
while (*from)
{
to[0]=*from;
to++;
from--;
}
to[0]='\0';
}
[\code]
http://www.mowker.com/qklb/


#38


引用 37 楼 imowker 的回复:
好,果然厉害
引用 5 楼 lsrongge 的回复:

[code=c/c++]
void strCpy(char *to,const char * from)
{
while(*from)
{
from++;
}
from--;
while (*from)
{
to[0]=*from;
to++;
from--;
}
to[0]='\0';
}
[\co……

五楼的从后面往前走时,不能准确到初始地址的.你们试下就知道,后面又一串乱码.

#39


31楼才不错,5楼不行

#40


请问一下 指针作为参数在传递的时候是不是也会产生一份临时变量呢?参考5楼的代码 可以正确得出结果,不过在函数内部,指针指向的地址确实变了,而且在函数内部也没有回到初始地址。在主函数内,调用完成后,该指针又回到了初始位置,所以我想问下,指针在传递的时候是不是也会产生一份临时变量呢?在函数内部使用的只是一个临时变量?

#41


飞            指针

#42


引用 23 楼 betamark 的回复:
#include<stdio.h>
void Strcpy(char* to, const char *from) {
*to = '\0';
while (*from != '\0')
*(++to) = *(++from);
--to;
--from;
while (*to != '\0')
--to;
*to = *from;
while (*to != '\0') {……

没有人来说一下吗?

#43


引用 42 楼 betamark 的回复:
引用 23 楼 betamark 的回复:

#include<stdio.h>
void Strcpy(char* to, const char *from) {
*to = '\0';
while (*from != '\0')
*(++to) = *(++from);
--to;
--from;
while (*to != '\0')
--to;
*to = *from……

你检查一下 有没有'\0',如果用%s的话 不主动刷新缓冲区 不遇到这个符号是不会刷新的

#44


#include <stdio.h>

void strcyp(char *dest, const char *src);

int main(int argc, char *argv[])
{
char dest[64];
char src[64] = "123456789";
strcyp(dest, src);
printf("src  is #%s#\n", src);
printf("dest is #%s#\n", dest);
return 0;
}


void strcyp(char *dest, const char *src)
{
*(int *)dest = 0;
while(*src) {
(*(int *)dest)++;
++src;
}
src -= *(int *)dest;
dest += *(int *)dest;
*dest = '\0';
while('\0' != *src) {
*--dest = *src++;
}
return;
}
如果长度小于4(即sizeof(int);)的时候ls的自己验证讨论吧。

#45


另31楼方法很不错。

#46


void
str_cpy( char *to, const char *from )
{
*to = 1;     //对起始位置做标记
while( '\0' != *from ) {
*(++to) = 2;     //保证缓冲区to中不除第1位外均不为1及0
from++;
}

*to = 0;      //对终止位置做标记

while( 1 != *to )      //回到起始位置
to--;

while( 0 != *to )      //复制字符串
*to++ = *(--from);

*to = '\0';
}

#47


这题很有代表性啊

#48


5楼明显是错的。这种题目的原意应该是考递归吧。。。
2种方法,一个是递归,如28楼,但我不知道形参算不算变量啊?一个是偷机想办法在to里变相保存from的长度,比如31楼,但如果是用这种方法,就是把to当成一个变量来用了,和出题的思路不符。
给出一个较简单的递归例子。
void do_strcyp( char** to, char* from )
{
    if( *from != '\0' )
    {
        do_strcyp( to, from++ );
        **to = *from; (*to)++;
    }
}

void strcyp(char * to,const char * from)
{
    do_strcyp( &to, from );
    *to = '\0';
}

程序没调过,大概那么个意思吧,可能有错误。

#49



void str_cpy(char *to, const char *from)
{

assert(to && from);

while(*from++);

from -= 2;

while(*from)
{
*to++ = *from--;
}

*to = '\0';
}

#50


这题有那么经典?那么难么?晕死

#1


没有人看吗,想了一下午都没想出来,求高手指教哇!请注意要求!!

#2


from++到‘\0’ - 1处,赋值给to,to就指向逆序的from了

#3


引用 2 楼 c_helloworld 的回复:
from++到‘\0’ - 1处,赋值给to,to就指向逆序的from了

呵呵,不做评论

#4


求给出代码啊

#5


[code=c/c++]
void strCpy(char *to,const char * from)
{
while(*from)
{
from++;
}
from--;
while (*from)
{
to[0]=*from;
to++;
from--;
}
to[0]='\0';
}
[\code]

#6


递归?

#7



void strCpy(char *to,const char * from)
{
while(*from)
{
from++;
}
from--;
while (*from)
{
to[0]=*from;
to++;
from--;
}
to[0]='\0';
}

#8


[code=c/c++] 
void strCpy(char *to,const char * from) 

while(*from) 

from++; 

from--; 
while (*from) 

to[0]=*from; 
to++; 
from--; 

to[0]='\0'; 

[code]

#9


void Ch_cpy(char a[],int n)
{
char temp;
int i,j;
int m=n/2;
for(i=0;i<m;i++)
{j=n-1-i;
temp=a[i];a[i]=a[j];a[j]=temp;
}
return;
}
main()
{
int i;
char a[11]={"helloworld!"};
for(i=0;i<10;i++)
printf("%c",a[i]);
printf("\n");
Ch_cpy(a,10);
for(i=0;i<10;i++)
printf("%c",a[i]);
printf("!");
system("pause");

}

我也是初学着,不过程序可用.

#10


不能使用其他的变量?也就是只有from和to?

#11


第二个while(*from)是什么意思呢?

#12


引用 10 楼 wjl19890711 的回复:
不能使用其他的变量?也就是只有from和to?

Yes!

#13


引用 11 楼 betamark 的回复:
第二个while(*from)是什么意思呢?

第一个到尾巴上
第二个再头上顺便给to赋值

#14



void strcyp(char * to,const char * from)
{
ASSERT(to);
ASSERT(from);
while(from!=NULL)
{
 *to = *from;
     to++;from++;
}
*to = '\0';
}

#15


C语言经典笔试题?

#16


#include<iostream>
using namespace std;
char * rstrcpy(char *to,const char*from)
{
to=to+3;
for(int i=0;i!=4;i++)
{
*(to-i)=*(from+i);
}
*(to+1)='\0';

return to;
}
int main()
{
const char *from="1234";
    char *to;
to=(char *)malloc(sizeof(char)*5);;
rstrcpy(to,from);
cout<<to<<endl;
    return 0;
}

#17


引用 15 楼 udbwcso 的回复:
C语言经典笔试题?

难道这个还不经典?

#18


5楼,高手……

#19


#include <locale>
#include <iostream>
using namespace std;


void rstrcpy(char *from,char *to)
{
  int i= strlen(from)-1;
  while(i>=0)
  {
    *to=from[i];
to++;
i--;
  } 
}

int main( )   
{
   char t[5]="0000";
//for(int i = 0;i<16;i++ )
   char s[5]="1234";
   rstrcpy(s,t);
   printf("%s",t);
}

#20


感觉应该用递归,能力有限。。

#21


经典啊!

#22


引用 19 楼 wcg_jishuo 的回复:
#include <locale>
#include <iostream>
using namespace std;


void rstrcpy(char *from,char *to)
{
  int i= strlen(from)-1;
  while(i>=0)
  {
    *to=from[i];
to++;
i--;
  } 
}

int mai……

你用了strlen函数

#23


#include<stdio.h>
void Strcpy(char* to, const char *from) {
*to = '\0';
while (*from != '\0')
*(++to) = *(++from);
--to;
--from;
while (*to != '\0')
--to;
*to = *from;
while (*to != '\0') {
*(to++) = *(from--);
}
}

int main() {
char buf[4];
Strcpy(buf, "456789");
printf("buf=%s\n", buf);
return 0;
}
自己写的代码。为什么我去掉printf("buf=%s\n",buf);中的"\n"就什么都打印不出来呢,是缓冲区已满吗?

#24


#include <stdio.h>
#include <malloc.h>

void strcyp(char *to,const char *from);

main(){
   char *from = "hello,the world!" ;
   char *to ;
   strcyp(to,from);
   getch();
}

void strcyp(char *to,const char *from){
   int i = 0 ;
   char *to_ ;
   printf("%s\n",from);
   while(*from++!='\0'){
        i++ ;
   }
   from = from -2 ; /*在这里需要注意的是,while里的*from++,即使判断为‘\0’,让会执行++操作,不知道是不是winTC的缘故*/
   printf("%c \n",*from);
   printf("i=%d\n",i);
   to = (char *)malloc(sizeof(char)*i) ;
   to_ = to ; /*为to的开头*/
   while(i--){
      *to++ = *from-- ;1));
   }
   *to = '\0';
   printf("\n%s\n",to_);
}

#25



#include <stdio.h>
#include <malloc.h>

void strcyp(char *to,const char *from);

main(){
   char *from = "hello,the world!" ;
   char *to ;
   strcyp(to,from);

   getch();
}

void strcyp(char *to,const char *from){
   int i = 0 ;
   char *to_ ;
   printf("%s\n",from);
   while(*from++!='\0'){
        i++ ;
   }
   from = from -2 ;*在这里需要注意的是,while里的*from++,即使判断为‘\0’,让会执行++操作,不知道是不是winTC的缘故*/
   printf("%c \n",*from);
   printf("i=%d\n",i);
   to = (char *)malloc(sizeof(char)*i) ;
   to_ = to ;/*为to的开头*/
   while(i--){
      *to++ = *from-- ;1));
   }
   *to = '\0';
   printf("\n%s\n",to_);
}

#26


五楼不错

#27


引用 26 楼 hard1rock 的回复:
五楼不错

我也是这么认为的,呵呵

#28


递归的思路还是正确的,不知道这个成不

int do_strcyp( char* to, char* from )
{
if( *from == 0 )
{
return 0;
}
else
{
*(to + do_strcyp( to, from+1 )) = *from;
return do_strcyp( to, from+1 ) + 1;
}
}

void strcyp( char* to, char* from )
{
*(to + do_strcyp( to, from )) = 0;
}

#29


引用 21 楼 zichen0422 的回复:
经典啊!

int strlen(char *source, char target,int len)
{
int count = 0;
while(count!=len)
{
if (target ==*source ++)
break;
++count;
}
int count;
}

#30


此题出有的问题[写C语言的拷贝函数, 要求复制字符串,并且将复制后的字符串逆序 比如from中是1234, 则to中是4321]
如果不用库函数的话,如何复制字符串呢?也就是不申请内容,无法达到题要求.
5楼的,也没有考虑to指向的内存问题. 

#31



char *converse_copy(char *dest, const char *src)
{
    // 确定dest的首位置
    *dest = '\0';
    while (*src)
    {
        ++src;
        *(++dest) = ' ';
    }
    // 指向最后一个字符
    src--;
    // 确定dest的尾位置
    *dest = '\0';
    // 到首位置
    while (*--dest);
    *dest++ = *src--;
    while (*dest)
    {
        *dest++ = *src--;
    }
    src++;
    while (*src)
    {
        ++src;
        --dest;
    }
    return dest;
}

#32



        char * strcpy(char * strDest,const char * strSrc) 
        { 
             if ((strDest==NULL)||(strSrc==NULL)) //[1] 
                      throw "Invalid argument(s)"; //[2] 
             char * strDestCopy=strDest;    //[3] 
             while ((*strDest++=*strSrc++)!='\0'); //[4] 
             return strDestCopy; 
        } 



http://blog.csdn.net/hondely/article/details/6883155  
自己写了一点

#33


 

void strcopy(char *to,char *from)
{
  *to='\0';
  ++from;
  ++to;
  while(*from)
  {  
    *to=*from;
    from++;
    to++;
  }
    *to='\0';
     to--;
   while(*to!='\0')
   to--;
   from--;
   *to=*from;
   while(*to!='\0')
   {      
          *to=*from;
          to++;
          from--;   
   
   } 
  return;  
  
}
这个可以用,楼主试下

#34



#include<stdlib.h>
void change(char *to,const char * from)
{
*to='\0';
        while(*from!='\0')
        {
            from++;to++;
*to=*from;
        }
to--;*to='\0';to--;
        from--;

while(*to!='\0')
to--;

while(1)
{
*to=*from;

to++;from--;
if(*to=='\0')
{
*to=*from;
break;
}

}



}
int main(int argc,char *argv[])
{
char a[6];
char b[6];
memset(b,0,sizeof(b)); //初始化
strcpy(a,"12345"); //给a赋值a=12345
change(b,a); //倒序函数b=54321
printf("b=%s\n",b);
return 0;
}

花了1个小时写出来的,在linux下经过测试,b=54321

#35


如果不用递归实在是蛮简单的啊

#36


char* str_rev(const char* src,char* dst)
{
if(src == 0 || dst == 0)
return 0;

int i_len = 0; //作用是计算字符串长度
const char* temp = src;
for(;*src++ != 0;i_len++)
;
dst = dst+i_len;
while(*temp !=0)
*--dst= *temp++;
return dst;
}

#37


好,果然厉害
引用 5 楼 lsrongge 的回复:
[code=c/c++]
void strCpy(char *to,const char * from)
{
while(*from)
{
from++;
}
from--;
while (*from)
{
to[0]=*from;
to++;
from--;
}
to[0]='\0';
}
[\code]
http://www.mowker.com/qklb/


#38


引用 37 楼 imowker 的回复:
好,果然厉害
引用 5 楼 lsrongge 的回复:

[code=c/c++]
void strCpy(char *to,const char * from)
{
while(*from)
{
from++;
}
from--;
while (*from)
{
to[0]=*from;
to++;
from--;
}
to[0]='\0';
}
[\co……

五楼的从后面往前走时,不能准确到初始地址的.你们试下就知道,后面又一串乱码.

#39


31楼才不错,5楼不行

#40


请问一下 指针作为参数在传递的时候是不是也会产生一份临时变量呢?参考5楼的代码 可以正确得出结果,不过在函数内部,指针指向的地址确实变了,而且在函数内部也没有回到初始地址。在主函数内,调用完成后,该指针又回到了初始位置,所以我想问下,指针在传递的时候是不是也会产生一份临时变量呢?在函数内部使用的只是一个临时变量?

#41


飞            指针

#42


引用 23 楼 betamark 的回复:
#include<stdio.h>
void Strcpy(char* to, const char *from) {
*to = '\0';
while (*from != '\0')
*(++to) = *(++from);
--to;
--from;
while (*to != '\0')
--to;
*to = *from;
while (*to != '\0') {……

没有人来说一下吗?

#43


引用 42 楼 betamark 的回复:
引用 23 楼 betamark 的回复:

#include<stdio.h>
void Strcpy(char* to, const char *from) {
*to = '\0';
while (*from != '\0')
*(++to) = *(++from);
--to;
--from;
while (*to != '\0')
--to;
*to = *from……

你检查一下 有没有'\0',如果用%s的话 不主动刷新缓冲区 不遇到这个符号是不会刷新的

#44


#include <stdio.h>

void strcyp(char *dest, const char *src);

int main(int argc, char *argv[])
{
char dest[64];
char src[64] = "123456789";
strcyp(dest, src);
printf("src  is #%s#\n", src);
printf("dest is #%s#\n", dest);
return 0;
}


void strcyp(char *dest, const char *src)
{
*(int *)dest = 0;
while(*src) {
(*(int *)dest)++;
++src;
}
src -= *(int *)dest;
dest += *(int *)dest;
*dest = '\0';
while('\0' != *src) {
*--dest = *src++;
}
return;
}
如果长度小于4(即sizeof(int);)的时候ls的自己验证讨论吧。

#45


另31楼方法很不错。

#46


void
str_cpy( char *to, const char *from )
{
*to = 1;     //对起始位置做标记
while( '\0' != *from ) {
*(++to) = 2;     //保证缓冲区to中不除第1位外均不为1及0
from++;
}

*to = 0;      //对终止位置做标记

while( 1 != *to )      //回到起始位置
to--;

while( 0 != *to )      //复制字符串
*to++ = *(--from);

*to = '\0';
}

#47


这题很有代表性啊

#48


5楼明显是错的。这种题目的原意应该是考递归吧。。。
2种方法,一个是递归,如28楼,但我不知道形参算不算变量啊?一个是偷机想办法在to里变相保存from的长度,比如31楼,但如果是用这种方法,就是把to当成一个变量来用了,和出题的思路不符。
给出一个较简单的递归例子。
void do_strcyp( char** to, char* from )
{
    if( *from != '\0' )
    {
        do_strcyp( to, from++ );
        **to = *from; (*to)++;
    }
}

void strcyp(char * to,const char * from)
{
    do_strcyp( &to, from );
    *to = '\0';
}

程序没调过,大概那么个意思吧,可能有错误。

#49



void str_cpy(char *to, const char *from)
{

assert(to && from);

while(*from++);

from -= 2;

while(*from)
{
*to++ = *from--;
}

*to = '\0';
}

#50


这题有那么经典?那么难么?晕死