rt

解决方案 »

  1.   

    不知道你有没有调用过dll文件,我想原理应该差不多,可能vc或是已经安装了它功能的实现的dll文件string.h只是申明而已,以上是我猜的,不过我却的挺有道理,呵呵
      

  2.   

    不过如此而已。
    void str_cpy(char* dest,const char* source)
    {
       while(*dest++=*source++);
    }
      

  3.   

    .h只声明函数,编译时链接lib才有这个功能,看不到实现
      

  4.   

    strcpy是可以看见的啊!
    stl模板库中也有定义
    和zzqzzq(zzq)类似 
      

  5.   

    谢谢!但stl模板库去哪里找呢?自己可以写,但我想看一看microsoft的源码以更能清楚,为什么还要返回char*呢?
    看一看好处多多呀linux很难找的,主要是我对它不熟悉,而且现在我自己的电脑也没有用(原因太多,这里不方便说了),所以现在linux环境是找不到的,没法看大家再帮个忙,看能不能有其它办法,谢谢了先!
      

  6.   

    char * __cdecl strcpy(char * dst, const char * src)
    {
            char * cp = dst;        while( *cp++ = *src++ )
                    ;               /* Copy src over dst */        return( dst );
    }
      

  7.   

    "Microsoft Visual Studio\VC98\CRT\SRC"目录下面的"STRCAT.C"文件里面。
      

  8.   

    有时候函数原本不需要返回值,但为了增加灵活性如支持链式表达,可以附加返回值。例如字符串拷贝函数strcpy的原型:char *strcpy(char *strDest,const char *strSrc);strcpy函数将strSrc拷贝至输出参数strDest中,同时函数的返回值又是strDest。这样做并非多此一举,可以获得如下灵活性:    char str[20];    int  length = strlen( strcpy(str, “Hello World”) );
      

  9.   

    我的Microsoft Visual Studio\VC98下没有CRT目录
    我搜索strcat*,没有找到一个文件
    我只是知道strcpy可以copy一个string
    但不知道为什么还要返回值,按照楼上热心朋友说的返回值的原因,有道理,但我感觉这不够充分用F11跟进strcpy函数?撒,不能跟进,一用F11就说找不到***.asm文件,要求自己定位,当然我也找不到了,搜索了几遍都搜不出来呀,那就是根本不存在这个文件了kao,看来是看不到这个函数的源代码了,郁闷呀
      

  10.   

    可能是你没有把VC装全吧。我说的那个原因是从《高质量C++编程指南》中抄下来的。我认为这个原因已经足够了。:)
      

  11.   

    除了strcat和strcpy之外,还有类似的函数吗?我是说像这两个函数一样,参数的类型和返回的类型一样,即结果中的参数值和函数的返回值是一样的函数,我以为很难找了吧?我以为,如果是为了方便的话,完全可以返回一个int型的值,直接表明copy了多少就可以了,没有必要这样。就像GetWindowText一样,返回的就是长度,却没有返回一个一样的字符串
      

  12.   

    返回一个指针所能增加的好处和用途远远比返回一个长度多。例如,如果你想直接引用拷贝之后的字符串,strcpy有这样的返回值,就能让你少写一句代码。
      

  13.   

    不,我以为如果仅仅是为了这一点方便的话,microsoft的人肯定不会这么做
      

  14.   

    绝大部分函数的实现是被封装进lib文件中的
      

  15.   

    lib文件里边只有声明部分吧?
    dll里边声明和现实部分都有
      

  16.   

    page    ,132
            title   strcat - concatenate (append) one string to another
    ;***
    ;strcat.asm - contains strcat() and strcpy() routines
    ;
    ;       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
    ;
    ;Purpose:
    ;       STRCAT concatenates (appends) a copy of the source string to the
    ;       end of the destination string, returning the destination string.
    ;
    ;*******************************************************************************        .xlist
            include cruntime.inc
            .list
    page
    ;***
    ;char *strcat(dst, src) - concatenate (append) one string to another
    ;
    ;Purpose:
    ;       Concatenates src onto the end of dest.  Assumes enough
    ;       space in dest.
    ;
    ;       Algorithm:
    ;       char * strcat (char * dst, char * src)
    ;       {
    ;           char * cp = dst;
    ;
    ;           while( *cp )
    ;                   ++cp;           /* Find end of dst */
    ;           while( *cp++ = *src++ )
    ;                   ;               /* Copy src to end of dst */
    ;           return( dst );
    ;       }
    ;
    ;Entry:
    ;       char *dst - string to which "src" is to be appended
    ;       const char *src - string to be appended to the end of "dst"
    ;
    ;Exit:
    ;       The address of "dst" in EAX
    ;
    ;Uses:
    ;       EAX, ECX
    ;
    ;Exceptions:
    ;
    ;*******************************************************************************page
    ;***
    ;char *strcpy(dst, src) - copy one string over another
    ;
    ;Purpose:
    ;       Copies the string src into the spot specified by
    ;       dest; assumes enough room.
    ;
    ;       Algorithm:
    ;       char * strcpy (char * dst, char * src)
    ;       {
    ;           char * cp = dst;
    ;
    ;           while( *cp++ = *src++ )
    ;                   ;               /* Copy src over dst */
    ;           return( dst );
    ;       }
    ;
    ;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" in EAX
    ;
    ;Uses:
    ;       EAX, ECX
    ;
    ;Exceptions:
    ;*******************************************************************************
            CODESEG%       public  strcat, strcpy      ; make both functions available
    strcpy  proc
            push    edi                 ; preserve edi
            mov     edi,[esp+8]         ; edi points to dest string
            jmp     short copy_startstrcpy  endp        align   16strcat  proc        .FPO    ( 0, 2, 0, 0, 0, 0 )        mov     ecx,[esp+4]         ; ecx -> dest string
            push    edi                 ; preserve edi
            test    ecx,3               ; test if string is aligned on 32 bits
            je      short find_end_of_dest_string_loopdest_misaligned:                    ; simple byte loop until string is aligned
            mov     al,byte ptr [ecx]
            inc     ecx
            test    al,al
            je      short start_byte_3
            test    ecx,3
            jne     short dest_misaligned        align   4find_end_of_dest_string_loop:
            mov     eax,dword ptr [ecx] ; read 4 bytes
            mov     edx,7efefeffh
            add     edx,eax
            xor     eax,-1
            xor     eax,edx
            add     ecx,4
            test    eax,81010100h
            je      short find_end_of_dest_string_loop
            ; found zero byte in the loop
            mov     eax,[ecx - 4]
            test    al,al               ; is it byte 0
            je      short start_byte_0
            test    ah,ah               ; is it byte 1
            je      short start_byte_1
            test    eax,00ff0000h       ; is it byte 2
            je      short start_byte_2
            test    eax,0ff000000h      ; is it byte 3
            je      short start_byte_3
            jmp     short find_end_of_dest_string_loop
                                        ; taken if bits 24-30 are clear and bit
                                        ; 31 is set
    start_byte_3:
            lea     edi,[ecx - 1]
            jmp     short copy_start
    start_byte_2:
            lea     edi,[ecx - 2]
            jmp     short copy_start
    start_byte_1:
            lea     edi,[ecx - 3]
            jmp     short copy_start
    start_byte_0:
            lea     edi,[ecx - 4]
    ;       jmp     short copy_start;       edi points to the end of dest string.
    copy_start::
            mov     ecx,[esp+0ch]       ; ecx -> sorc string
            test    ecx,3               ; test if string is aligned on 32 bits
            je      short main_loop_entrancesrc_misaligned:                     ; simple byte loop until string is aligned
            mov     dl,byte ptr [ecx]
            inc     ecx
            test    dl,dl
            je      short byte_0
            mov     [edi],dl
            inc     edi
            test    ecx,3
            jne     short src_misaligned
            jmp     short main_loop_entrancemain_loop:                          ; edx contains first dword of sorc string
            mov     [edi],edx           ; store one more dword
            add     edi,4               ; kick dest pointer
    main_loop_entrance:
            mov     edx,7efefeffh
            mov     eax,dword ptr [ecx] ; read 4 bytes        add     edx,eax
            xor     eax,-1        xor     eax,edx
            mov     edx,[ecx]           ; it's in cache now        add     ecx,4               ; kick dest pointer
            test    eax,81010100h        je      short main_loop
            ; found zero byte in the loop
    ; main_loop_end:
            test    dl,dl               ; is it byte 0
            je      short byte_0
            test    dh,dh               ; is it byte 1
            je      short byte_1
            test    edx,00ff0000h       ; is it byte 2
            je      short byte_2
            test    edx,0ff000000h      ; is it byte 3
            je      short byte_3
            jmp     short main_loop     ; taken if bits 24-30 are clear and bit
                                        ; 31 is set
    byte_3:
            mov     [edi],edx
            mov     eax,[esp+8]         ; return in eax pointer to dest string
            pop     edi
            ret
    byte_2:
            mov     [edi],dx
            mov     eax,[esp+8]         ; return in eax pointer to dest string
            mov     byte ptr [edi+2],0
            pop     edi
            ret
    byte_1:
            mov     [edi],dx
            mov     eax,[esp+8]         ; return in eax pointer to dest string
            pop     edi
            ret
    byte_0:
            mov     [edi],dl
            mov     eax,[esp+8]         ; return in eax pointer to dest string
            pop     edi
            retstrcat  endp        end
      

  17.   

    #include<iostream.h>
    #include<string.h>
    #define LPCTSTR const unsigned char*
    int Istrlen(LPCTSTR lpString);
    void main()
    {
     unsigned char st[]="12345";
     LPCTSTR lpStr=st;
     cout<<Istrlen(lpStr)<<endl;
    }
    int Istrlen(LPCTSTR lpString)
    {
    return strlen((char*)lpString);
    }
      

  18.   

    当然都是汇编了,要不然的话,我怎么会说跟不进去呢?
    汇编慢慢看的话,也许能懂一点点,但那太慢了,还得一边研究
    也不知道到什么时候函数会结束,中间调用了什么函数
    很麻烦的不知道 richardxu2002(richard) 朋友是从哪里找来的,是源码吗?
      

  19.   

    char *strcpy(char *strDest, const char *strSrc)
    {
    char *strAddr; if ((strDest == NULL) || (strSrc == NULL))
    return NULL; strAddr = strDest;
    while ((*strDest++ = *strSrc++) != '\0'); return strAddr;
    }
      

  20.   

    to gai() :
    如果是你这样的话,就可以改成下面这样子:会更简单一点
    char *strcpy(char *strDest, const char *strSrc)
    {
    if ((strDest == NULL) || (strSrc == NULL))
    return NULL; while ((*strDest++ = *strSrc++) != '\0'); return strDest;
    }但这样做有什么意义呢?我是说返回那那个strDest有什么意义呢?有意义,但意义不大,所以根据microsoft的作风,这样是不会返回这样意义不大的值,我想,肯定是其它什么返回值和理由
      

  21.   

    较这真干嘛
    又不是一个多么神秘的函数值得你去研究它的内部实现
    不就是返回值嘛
    当初编这函数的人也跟你一样是程序员,又不是神仙
    程序员嘛,在一些无关紧要的地方可以只按照自己的喜好来编要是当时是我编的,我一时心血来潮指定他返回个BOOL甚至是个void
    那以后它也就是这样了,难道你也非得找个理由出来?
      

  22.   

    strcpy这样的C函数不是微软制定的,是制定C语言规范的那些人说了算,微软只是实现它而已,当然,微软也有不安标准来的时候,只是不多。类似的情况也出现在C++标准中。你相信制定C标准的人这样做是有原因的,不错。但是原因非要是什么惊天动地的才可以吗?能以举手之劳带来的方便,当然要提供才是。
      

  23.   

    首先,我现在不知道你说的“好处”到底是什么了。其次,我想我已经把strcpy返回指针的好处说了出来,也许你认为这不是很“大”的“好处”,但是我相信这些“小”“好处”积累起来,会变成“大”的“好处”。相信制定标准C的那些专家会有最深的体会。这个函数是一个很简单的函数,就是自己实现也不难。它的作用就是那么多,不可能因为返回了一个指针就变得神秘莫测,也不能因为多了一个返回值就改变了本质变成另外一个东西,更不能因为多了一个返回值而“惊天动地”。
      

  24.   

    搂主,我的代码是F11,跟踪出来的,方法很简单,你在调用strcpy函数的地方设断点,按F5
    run到断点的时候再按F11就可以了,我后来仔细看了一下,这段代码的注释部分就是strcpy的C实现,方法和大家说的头差不多。至于为什么要返回一个指针,我认为最大的好处在于可以实现裢式表达式比如
    strlen(strcpy( pszA, pszB ) )这样的式子,其他的例子暂时想不出来,大家可以都自己去琢磨一下。其实用F11跟踪获取源码为一种很方便的方法:)
      

  25.   

    ……strcpy(pszD, strcyp(pszC, strcpy( pszA, pszB )))……