b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

c++ strchr函数_strchr函数返回_模拟实现strchr函数(8)

电脑杂谈  发布时间:2017-02-28 08:29:56  来源:网络整理

*s为数组名,ch为要填充的数,n为选择填充数组的长度(一般用sizeof(数组名))

#include<iostream>

#include<cstring>

using namespace std;

int main()

{

char a[5];

memset(a,'1',5);

for(int i=0;i<5;i)

cout<<a[i]<<"";

return 0;

}

输出结果:11111

#include<iostream>

#include<cstring>

using namespace std;

int main()

{

int a[5];

memset(a,0,sizeof(a));

for(int i=0;i<5;i)

cout<<a[i]<<" ";

return 0;

}

输出结果:0 0 0 0 0

void *memmove( void* dest, const void* src,size_t count );

由src所指内存区域复制count个字节到dest所指内存区域,如果src和dest出现重叠,函数会自动处理,返回dest的。

#include <stdio.h>

#include <string.h>

int main(void)

{

char s[]="Golden Global View";

memmove(s,s7,strlen(s)1-7);

printf("%s",s);

getchar();

return 0;

}

输出结果:GlobalView

#include<stdio.h>

#include<string.h>

int main()

{

char*s="GoldenGlobalView";

char d[20];

memcpy(d,s,(strlen(s)1));

printf("%s",d);

getchar();

return 0;

}

输出结果:GoldenGlobalView

#include<stdio.h>

#include<string.h>

int main()

{

char *s="GoldenGlobalView";

char d[20];

memcpy(d,s6,6); //从第6个字符(V)开始复制,连续复制6个字符(View)

d[6]='\0';

printf("%s",d);

return 0;

}

输出结果:Global

#include<stdio.h>

#include<string.h>

int main()

{

char src[]="******************************";

char dest[]="abcdefghijlkmnopqrstuvwxyz0123as6";

printf("destinationbeforememcpy:%s\n",dest);

memcpy(dest,src,strlen(src));


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-34960-8.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...