c program

2007-04-10 8:41 am
how to write a program that does the same job as strcat without using any library function??

回答 (1)

2007-04-10 11:48 am
✔ 最佳答案
#include

char * mystrcat(char * __restrict s, const char * __restrict append)
{
char * save = s;

for(; *s; ++s);
while(*s++ = *append++);
return(save);
}


//test program
int main (void){
char text[12] = "Hello";
puts(text);
puts(mystrcat(text, " world"));
return 0;
}

2007-04-10 03:54:48 補充:
修正 html 出唔到o既符號, 改為中文全形:#include<stdio.h>...char text[12] = ”Hello”; ...puts(mystrcat(text, ” world”)); ...


收錄日期: 2021-04-23 20:10:11
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070410000051KK00197

檢視 Wayback Machine 備份