Hit9 Blog Wiki Project Links Archives Resumé
Page: First UP Pre Next Back

C语言练习3:不用string库实现字符串连接

Fork me on GitHub

允许转载, 但转载请注明出处

Date:2012-08-11

头文件strcat.h:

#ifndef STRCAT_H
#define STRCAT_H 1
void strcat(char *a,const char *b)
{
    while ( *a!='\0' )
    {
        a++;
    }  
    while ( *b!='\0' )
    {
        *a++=*b++;
    }
}

测试这个函数:

#include <stdio.h>
#include <stdlib.h>
#include "strcat.h"
#include "strcpy.h"
int main(int argc, const char *argv[])
{
    char *p=(char *)malloc(12*sizeof(char));
    strcpy(p,"hello");
    strcat(p," world");
    printf("%s\n",p);
    return 0;
}

Support:mkdwiki