首页 > 其他 > 详细

strcpy的使用

时间:2016-01-31 13:20:13      阅读:224      评论:0      收藏:0      [点我收藏+]
1、数组
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
int main(void)
{
char ll[10]={0};

strcpy(str,"hello");//#include <string.h> 可以直接赋值给数组
printf("String is %s\n",str);
	//free(str); 这个free只能对应malloc 否则会报错

getch();
	return 0;
}
2、指针
#include <stdio.h>
#include <stdlib.h>//malloc
#include <conio.h>//getchar putchar
#include <string.h>//strcpy
int main(void)
{
char *str;
str=(char *)malloc(sizeof(char)*10);
if(str== NULL)
{
perror("malloc");
abort();
}
else
{
strcpy(str,"hello");//#include <string.h>
printf("String is %s\n",str);
		free(str);//这个free对应malloc
}
	getch();
	return 0;
}

strcpy的使用

原文:http://www.cnblogs.com/Study02/p/5173124.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!