CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C语言

有谁记得strcpy函数的原型

楼主lifenqidelphi(血)2002-03-28 16:19:21 在 C/C++ / C语言 提问

有谁记得strcpy函数的原型,  
  就是STRCPY是怎么样编写的。 问题点数:100、回复次数:15Top

1 楼prototype(原型)回复于 2002-03-28 16:25:45 得分 10

char*   strcpy(char*   s,   const   char*   ct);    
  Copies   ct   to   s   including   terminating   NUL   and   returns   s.    
  Top

2 楼neccui(PPC)回复于 2002-03-28 16:26:26 得分 0

char   *strcpy(char   *dest,   const   char   *src);  
   
  怎么编写?随便了,很多种写法。随手写一个。  
   
  char   *strcpy(char   *dest,   const   char   *src)  
  {  
      if(dest   ==   NULL)   return   NULL;  
      char   *   tmp=dest;  
      do  
      {  
            *(tmp++)=*src;  
      }while(*(src++));  
      return   dest;  
  }Top

3 楼prototype(原型)回复于 2002-03-28 16:27:52 得分 0

char*   strcpy(char*   s,   const   char*   ct)  
  {  
          while   (*s++   =   *ct++);  
  }Top

4 楼prototype(原型)回复于 2002-03-28 16:28:26 得分 20

char*   strcpy(char*   s,   const   char*   ct)  
  {  
          while   (*s++   =   *ct++);  
          return   s;  
  }Top

5 楼lifenqidelphi(血)回复于 2002-03-28 16:28:43 得分 0

我是说char*   strcpy(char*   s,   const   char*   ct)是怎么用语句实现的Top

6 楼cococut(小鱼的天空)回复于 2002-03-28 16:29:05 得分 10

#include   <string.h>  
  #include   <stdio.h>  
   
  void   main(   void   )  
  {  
        char   string[80];  
        strcpy(   string,   "Hello   world   from   "   );  
        strcat(   string,   "strcpy   "   );  
        strcat(   string,   "and   "   );  
        strcat(   string,   "strcat!"   );  
        printf(   "String   =   %s\n",   string   );  
  }  
   
   
  Output  
   
  String   =   Hello   world   from   strcpy   and   strcat!  
   
   
  Top

7 楼neccui(PPC)回复于 2002-03-28 16:31:01 得分 30

to   prototype(原型)   你的代码是错误的。  
  应该这样才对。  
     
  char*   strcpy(char*   s,   const   char*   ct)  
  {  
          char   *tmp   =   s;  
          while   (*s++   =   *ct++);  
          return   tmp;  
  }    
     
     
   
  Top

8 楼lifenqidelphi(血)回复于 2002-03-28 16:32:51 得分 0

我的意思是microsoft写的原型。Top

9 楼prototype(原型)回复于 2002-03-28 16:35:21 得分 0

neccui(PPC)   is   right.Top

10 楼prototype(原型)回复于 2002-03-28 16:37:07 得分 0

neccui(PPC)   is   right.Top

11 楼neccui(PPC)回复于 2002-03-28 16:40:19 得分 0

to     lifenqidelphi(血)   ,   不要用错误的术语。  
   
  所谓原型,就是指。  
  char*   strcpy(char*   s,   const   char*   ct);    
  这一句话。  
   
  你想要的是"实现",不是原型。Top

12 楼lifenqidelphi(血)回复于 2002-03-28 16:45:59 得分 0

哈哈哈。。。对对,是应说怎么实现。不过大家能理解是这个意思  
  就行了嘛。我是说的microsoft是怎么实现的。而不是我们自己  
  用的相同的方法。Top

13 楼gigix(透明)回复于 2002-03-28 16:58:33 得分 30

Visual   Studio   .NET里面有源代码:  
   
  /***  
  *char   *strcpy(dst,   src)   -   copy   one   string   over   another  
  *  
  *Purpose:  
  *               Copies   the   string   src   into   the   spot   specified   by  
  *               dest;   assumes   enough   room.  
  *  
  *Entry:  
  *               char   *   dst   -   string   over   which   "src"   is   to   be   copied  
  *               const   char   *   src   -   string   to   be   copied   over   "dst"  
  *  
  *Exit:  
  *               The   address   of   "dst"  
  *  
  *Exceptions:  
  ****************************************************************/  
   
  char   *   __cdecl   strcpy(char   *   dst,   const   char   *   src)  
  {  
                  char   *   cp   =   dst;  
   
                  while(   *cp++   =   *src++   );       /*   Copy   src   over   dst   */  
   
                  return(   dst   );  
  }  
   
  我有点想不通:为什么不用memcpy来实现呢?谁能告诉我?Top

14 楼lifenqidelphi(血)回复于 2002-03-28 17:11:29 得分 0

memcpy的原型   为  
  void   *memcpy(void   *to,const   *from,size_t   count);  
  它是复制conunt个字符。Top

15 楼prototype(原型)回复于 2002-03-28 17:13:57 得分 0

because   you   don't   know   the   length   of   the   string   'scr'.  
  furthermore,   'memcpy'   is   likely   implemented   in   a   similar   way.Top

16 楼neccui(PPC)回复于 2002-03-28 17:15:16 得分 0

to   gigix:  
  基于性能考虑。Top

17 楼lifenqidelphi(血)回复于 2002-06-13 12:48:39 得分 0

kkkkTop

相关问题

  • strpos函数原型
  • OpenAs_RunDLL的函数原型?
  • Singnal的函数原型
  • 函数原型问题
  • 函数原型的问题!
  • 函数原型作用域的疑问
  • 突然忘记INPUTBOX函数的原型,谁能给我此函数原型!QUICKLY!
  • 在MSDN里找不到mencpy(),get(),strcpy(),strcmp()....的函数原型?在哪里才能找到啊?我现在只剩下40分了
  • 函数原型和函数定义一个问题请赐教!谢谢!!!
  • 求助:有C++的函数原型,如何在C#中创建托管函数原型

关键词

  • c++
  • 原型
  • strcpy
  • ct
  • dst
  • strcat
  • dest
  • src
  • memcpy
  • 实现

得分解答快速导航

  • 帖主:lifenqidelphi
  • prototype
  • prototype
  • cococut
  • neccui
  • gigix

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo