Strcopy函數的書寫

#include <stdio.h>io

char *strcopy(char *str_dest, const char *str_source);
char *strncopy(char *str_dest, const char*str_source, int n);class

int main(int argc, char *argv)
{
 char *p;
 char *q;
 char str1[128], str2[128];
 p = strcopy(str1, "hello world");
 q = strncopy(str2, "yshous love yanan!", 18);
 printf("%s\n", p);
 printf("%s\n", q);
 return 0;
}gc

 char *strcopy(char * str_dest, const char * str_source)
{
 char *p;
 p = str_dest;
 while(*(str_source) !='\0')
 {
  *str_dest = *str_source;
  str_dest++;
  str_source++;
 }
 *str_dest = '\0';
 return p;
}di

char *strncopy(char * str_dest, const char * str_source, int n)
{
 char *p;
 int i;
 p = str_dest;
 for(i = 0; i < n; i++)
 {
  *(str_dest++) = str_source[i];
 }
 *str_dest = '\0';
 return p;
}while

相關文章
相關標籤/搜索