久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

C語(yǔ)言中strcpy,strcmp,strlen,strcat函數(shù)原型

 白楊4546 2016-03-29
#include
#include
char *strcpy(char *strDest, const char *strSrc) {
    char *address=strDest;
    assert((strDest!=NULL) &&  (strSrc!=NULL));
    while(*strSrc!='\0') {
        *strDest++=*strSrc++;
    }
    *strDest='\0';
    return address;
}
char *strcat(char *strDest, const char *strSrc) {
    char *address=strDest;
    assert((strDest!=NULL) &&  (strSrc!=NULL));
    while(*strDest!='\0') {
        strDest++;
    }
    while(*strSrc!='\0') {
        *strDest++ =* strSrc++;
    }
    *strDest='\0';
    return address;
}
nt strcmp(const char *str1,const char *str2) {
    assert((*str1!='\0' && *str2!='\0'));
    while (*str1 && *str2 && *str1==*str2) {
        str1++;
        str2++;
    }
    return *str1-*str2;
}
int new_strlen(const char *str) {
    assert(str != NULL);
    int len = 0;
    while (*str++ != '\0') {
        ++len;
    }
    return len;
}
void *memcpy(void *dst, void *src, size_t n) {
    char *dp = (char*)dst;
    char *sp = (char*)src;
    assert((src!=0) && (dst!=0) && n>0);
    while (n--) {
        *(dp++) = *(sp++);
    }
    *dp='\0';
    return dst;
}
void *new_memmove(void *dst, const void *src, int n) {
    char *dp = (char *)dst;
    char *sp = (char *)src;
    assert((src != 0)&&(dst != 0) && (n > 0));
    if (sp > dp || (sp+n) < dp) {
        while(n--)
            *(dp++)=*(sp++);
        *dp='\0';
    }else if (sp < dp){
        sp += n;
        dp += n;
        *dp = '\0';
        while(n--)
            *(--dp) = *(--sp);
    }
    return dst;
}
int main() {
    char dest[10];
    char* src = "test!";
    char* ret = strcpy(dest, src);
    printf("Test strcpy ret is :%s\n", ret);
    char cat1str[20] = "cat1";
    char* cat2str = "cat2";
    printf("Test strcat ret is :%s\n", strcat(cat1str, cat2str));
    char *len = "len";
    printf("Test strlen ret is :%d\n", new_strlen(len));
    char mem_dest[20];
    char* mem_src = "the src test memcpy";
    printf("Test memcpy ret is :%s\n", memcpy(mem_dest, mem_src, 10));
    char mv_dest[20];
    char* mv_src = "the src test memmove";
    printf("Test memmove ret is :%s\n", new_memmove(mv_dest, mv_src, 10));
}

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn),。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類(lèi)似文章 更多