1.strcpy的实现char * my_strcpy(char * s1, char * s2){ assert(s1 != NULL&&s2 != NULL); char *res = s1; while ((*(res++) = *(s2++))!='\0'); ret...
分类:
其他好文 时间:
2015-06-14 22:33:01
阅读次数:
133
先来看两段代码--
错误代码:
#include "string.h"
#include
#include
void test(char ** dest, char * src, int n) {
(*dest) = (char*) malloc(sizeof(char) * n);
strcpy(*dest, src);
}
int main(int argc, char** a...
分类:
系统相关 时间:
2015-06-13 17:10:41
阅读次数:
211
strcpy_s和strcpy()函数功能几乎相同。strcpy函数。就象gets函数一样,它没有方法来保证有效的缓冲区尺寸,所以它仅仅能假定缓冲足够大来容纳要拷贝的字符串。在程序执行时,这将导致不可预料的行为。用strcpy_s就能够避免这些不可预料的行为。这个函数用两个參数、三个參数都能够,仅仅...
分类:
其他好文 时间:
2015-06-11 22:38:44
阅读次数:
147
程序在Dev-C++5.5.3版本运行结构体的使用给结构体赋值,打印出结构体中学生姓名,分数,平均分#include #include #include #include #include //不用.h的话可能下面的strcpy用不了 #include using namespace std; i....
分类:
编程语言 时间:
2015-06-09 11:34:45
阅读次数:
153
周末赶数据结构的作业,整理的一些关于C语言中字符数组的困惑与解答。1.赋值C语言中,给字符数组char s[]赋值使用strcpy (在string.h头文件中)#include #include int main(){ char test[3][4]; strcpy(test[0], "abc")...
分类:
编程语言 时间:
2015-06-08 11:13:59
阅读次数:
200
int strlen(char* s){ int ret = 0; while(*s != 0) { ret++; *s++; } return ret;}char* strcpy(char* dest, char* src){ cha...
分类:
其他好文 时间:
2015-06-07 21:28:49
阅读次数:
114
#include
#include
using namespace std;
class String
{
public:
String(const char *str = " ")
{
m_data = new char[strlen(str) + 1];
strcpy(m_data, str);
count++;
}
String(const String &s)
...
分类:
编程语言 时间:
2015-06-05 22:49:07
阅读次数:
162
// 深拷贝,异常安全的深赋值
#include
#include
using namespace std;
class String
{
public:
String(const char *str = " ")
{
m_data = new char[strlen(str) + 1];
strcpy(m_data, str);
}
String(const String...
分类:
编程语言 时间:
2015-06-05 17:32:26
阅读次数:
144
大家一般觉得名不见经传strcpy函数实现不是非常难,流行的strcpy函数写法是:char *my_strcpy(char *dst,const char *src){ assert(dst != NULL); assert(src != NULL); char *ret = dst; while...
分类:
其他好文 时间:
2015-06-04 19:00:57
阅读次数:
127
记录一个简单的栈溢出的实例,具体的分析以后加进去。 程序源代码buffer.c: #include #include void fun1(char *input) { char buffer[10]; strcpy(buffer,input); printf("Call fun1,buffer=%s...
分类:
其他好文 时间:
2015-06-03 11:37:55
阅读次数:
93