指针 作业

指针做参数传递写出下面的函数,实现计算字符串长,字符串复制功能

int strlen(char *s)

void strcpy( char *s, char *t)

贴出你的代码

 1 #include<stdio.h>
2 int strlen(char *s)
3 {
4 int n = 0;
5 while(*s++!='\0')
6 {
7 n++;
8 }
9 return n;
10 }
11 void strcpy( char *s, char *t)
12 {
13 while((*t++=*s++)!='\0');
14 }
15 int main()
16 {
17 int k;
18 char str[1000],c[1000],*x,*y;
19 while(gets(str)!=NULL)
20 {
21 x = str;
22 y = c;
23 k = strlen(str);
24 printf("%d\n", k);
25 strcpy(x,y);
26 puts(c);
27 }
28 return 0;
29 }


原文地址:https://www.cnblogs.com/shangyu/p/2345678.html