1、关于strcpy函数。 书中说c风格的字符串尽量少用,strcpy这样的函数应该也要少用。这里讲这个函数主要是要通过本章课后练习第十题来讲一下前面提及的要点。巩固一下前几章的知识。写了一段,本来感觉自己写得不错了,结果和网上的一笔感觉还是差很多,也学到了很多,下面贴上网址供大家看看。...
分类:
编程语言 时间:
2015-04-16 23:13:21
阅读次数:
109
#include
#include
using namespace std;
class A
{
private:
char *a;
public:
A(char *aa)
{
a = new char[strlen(aa)+1]; // strcpy(a, aa); // }
~A()
{
...
分类:
其他好文 时间:
2015-04-15 09:39:59
阅读次数:
100
随便定义一个char类型字符串数组,此以char string[] = "iphone";为例。实现strlenchar string[] = "iphone"; int i = 0; while (string[i] != '\0') { i ++; } printf("%d", i...
分类:
其他好文 时间:
2015-04-15 09:28:53
阅读次数:
119
strcpy和memcpy都是标准C库函数,它们有下面的特点。 strcpy提供了字符串的复制。即strcpy只用于字符串复制,并且它不仅复制字符串内容之外,还会复制字符串的结束符。已知strcpy函数的原型是:char* strcpy(char* dest, const char* src); m...
分类:
其他好文 时间:
2015-04-14 09:52:00
阅读次数:
120
堆内存释放,是从堆顶开始。那么如果堆中间的一块区域,大部分内存都释放了,堆顶还有一些会怎么样呢?
我们来看个例子:
#include
#include
#include
#include
int main()
{
char *p[11];
int i;
for(i=0;i
{
p[i]=(char *)malloc(1024*2);
strcpy(p[i],"12...
分类:
其他好文 时间:
2015-04-13 16:40:36
阅读次数:
624
1. Inconsist length.char a3[2];char *a = "Itis "strcpy(a3, a); It is wrong. a3 will be correct, but a is missing. memcpy(a3, a, sizeof(char)* 2); It w...
分类:
其他好文 时间:
2015-04-12 13:13:36
阅读次数:
220
1、错误 1
error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
d:\codelibra...
分类:
其他好文 时间:
2015-04-10 13:38:41
阅读次数:
102
一些小问题,避免出现低级错误。1、strcmp(s1,s2): 字符串指针不见'\0'不回头,这个常在与单个字符作比较时写着写着就忘了.char* p_ch1="this is an example!";char* p_ch2="h";printf("%d ",strcmp(p_ch1+1,p_ch...
分类:
其他好文 时间:
2015-04-09 23:29:57
阅读次数:
144
#include
void my_strcpy(char* dest,const char* str)
{
if(NULL != dest || NULL != str)
{
while(((*dest++) = (*str++)))//注意运算的优先级
{
;
}
}
*dest = '\0';...
分类:
其他好文 时间:
2015-04-09 17:24:20
阅读次数:
89
#include
#include
using namespace std;
class string1
{
private:
char *str;
public:
string1(const char *s)
{
str = new char[strlen(s) + 1];
strcpy(str,s);
cout<<"str...
分类:
编程语言 时间:
2015-04-09 17:23:38
阅读次数:
132