strcpy函数学习
strcpy的功能如下:
#include<stdio.h>
#include<string.h> int main(void)
{
char* str1="hello1";
char* str2="hello2";
printf("str1=%s \n",str1);
printf("str2=%s \n",str2);
strcpy(str1,str2);
printf("str1=%s \n",str1);
printf("str2=%s \n",str2);
return ;
}
运行结果:
len@DESKTOP-BDP8J2M /cygdrive/e/c_study
$ gcc strcpy.c -o strcpy
len@DESKTOP-BDP8J2M /cygdrive/e/c_study
$ ./strcpy.exe
str1=hello1
str2=hello2
Segmentation fault (核心已转储)
例子2:
#include<stdio.h>
#include<string.h> int main(void)
{
char str1[]="hello1";
char* str2="hello2";
printf("str1=%s \n",str1);
printf("str2=%s \n",str2);
strcpy(str1,str2);
printf("str1=%s \n",str1);
printf("str2=%s \n",str2);
return ;
}
运行结果:
len@DESKTOP-BDP8J2M /cygdrive/e/c_study
$ gcc strcpy.c -o strcpy
len@DESKTOP-BDP8J2M /cygdrive/e/c_study
$ ./strcpy.exe
str1=hello1
str2=hello2
str1=hello2
str2=hello2
例子1和例子2的结论和随笔"静态内存"遇到的问题一样,strcpy的dest实参不可以是char*,必须是char[],即要是预先分配的字符内存空间。
strcpy函数学习的更多相关文章
- Python3中的字符串函数学习总结
这篇文章主要介绍了Python3中的字符串函数学习总结,本文讲解了格式化类方法.查找 & 替换类方法.拆分 & 组合类方法等内容,需要的朋友可以参考下. Sequence Types ...
- Drools 函数学习
Drools 函数学习 函数是定义在规则文件当中一代码块,作用是将在规则文件当中若干个规则都会用到的业务操作封装起来,实现业务代码的复用,减少规则编写的工作量.函数的编写位置可以是规则文件当中 pac ...
- C语言(函数)学习之strstr strcasestr
C语言(函数)学习之[strstr]&[strcasestr]一.strstr函数使用[1]函数原型char*strstr(constchar*haystack,constchar*needl ...
- strcpy函数的实现
strcpy函数的实现 大家一般认为名不见经传strcpy函数实现不是很难,流行的strcpy函数写法是: char *my_strcpy(char *dst,const char *src) { a ...
- strcpy函数实现
1,strcpy最简便实现 char * strcpy_to (char *dst, const char *src) { char *address = dst; assert((dst != NU ...
- strcpy函数和strncpy函数的区别
strcpy函数和strncpy函数的原型介绍在我的另一篇文章中介绍了,见strcpy,strncpy,strlen等函数原型 strcpy:字串复制 原型:char *strcpy(char *de ...
- memcpy、memmove、memset及strcpy函数实现和理解
memcpy.memmove.memset及strcpy函数实现和理解 关于memcpy memcpy是C和C++ 中的内存拷贝函数,在C中所需的头文件是#include<string.h> ...
- strlen() 和 strcpy()函数
strlen() 和 strcpy()函数的区别,这两个一个是返回一个C风格字符串的长度,一个是对一个C风格字符串的拷贝,两个本来功能上是不同的,此外,他们还有一些细小的区别:strlen(" ...
- strcpy函数的C/C++实现
2013-07-05 14:07:49 本函数给出了几种strcpy与strncpy的实现,有ugly implementation,也有good implementation.并参考标准库中的imp ...
随机推荐
- error C2065: ‘__in’ : undeclared identifier
转自VC错误:http://www.vcerror.com/?p=1307 问题描述: 编译时出现: error C2065: '__in' : undeclared identifier error ...
- python 将图片存入mongodb,读取图片,gridfs模块
导入图片引入模块,其中gridfs模块不需要单独安装,引入了pymongo即可直接引入from pymongo import MongoClientfrom gridfs import *import ...
- 【翻译】Knowledge-Aware Natural Language Understanding(摘要及目录)
翻译Pradeep Dasigi的一篇长文 Knowledge-Aware Natural Language Understanding 基于知识感知的自然语言理解 摘要 Natural Langua ...
- idea新手教程 如何springmvc创建Maven项目
1.点击Create project,选择maven,勾选Create from archetype选择web-app,如图 2 输入 Group-Id //组织名,也是作者名 Arti ...
- 了解JSON Web令牌(JWT)
JSON Web Token(JWT)是目前最流行的跨域身份验证解决方案.今天给大家介绍JWT的原理和用法. 1.跨域身份验证 Internet服务无法与用户身份验证分开.一般过程如下. 1.用户向服 ...
- DOM查询的其他方法
document.body 保存的是body的引用 documen.documentElement 保存的是html根标签 document.all 代表页面中所有的元素 getElementsByC ...
- c# 编程--基础部分补全篇
C#基础 分支: switch switch(表达式) { case 具体值1: ...
- C# 编程--数组
数组 可以帮我我们一次声明存储多个相同类型的变量.用来解决同一类大量数据在内存存储和运算的功能特点:连续.同一类数据数组定义==>赋值==>取值 定义: int[] n ...
- CentOS7 配置163 yum源(详细步骤)
CentOS7 配置163 yum源 1)下载repo文件 wget http://mirrors.163.com/.help/CentOS7-Base-163.repo 2)备份并替换系统的r ...
- C语言实现Windows下获取IP和MAC地址。
C语言实现Windows下获取IP和MAC地址. #include <winsock2.h> #include <stdio.h> #include <stdlib.h& ...