/*=============================================================
熟悉字符串指针作为函数参数
==============================================================
作者:最后的村长
时间:2009年10月28日
工具:DEV C++ 4.9.9.2
version:1.0
==============================================================*/
#include <stdio.h>
#include <stdlib.h>
/*=============================================================*/
void copy_string1(char *p1,char *p2)//以字符串指针作为函数参数
{
int i=0;
while(*p2!='\0')
{
*p1=*p2;
p1++;p2++;
}
*p1='\0';
}
void copy_string(char from[],char to[])//以 字符数组作为函数参数
{
int i=0;
while(from[i]!='\0')
{
to[i]=from[i];
i++;}
to[i]='\0';
}
int main()
{
char a[]="I am a teacher.";
char b[]="you are a student";
char c[5];//字符数组的大小在此并没有特别的意义
char *p1,*p2;
p1=a;p2=b;
printf("string a=%s\nstring b=%s\n",a,b);
copy_string1(c,p1);
printf("string c=%s\nstring a=%s\n",c,a);
copy_string(b,a);
printf("\nstring a=%s\nstring b=%s\n",a,b);
system("PAUSE");
return 0;
}
正文
熟悉字符串指针作为函数参数2009-10-08 12:23:00
【评论】 【打印】 【字体:大 中 小】 本文链接:http://blog.pfan.cn/cunzhang/49007.html
阅读(3110) | 评论(0)
版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!
评论