#include<stdio.h>
#include<assert.h>
void *my_memset(void *buffer,char c,int count){
assert(buffer);
char *temp;
int count_temp=count;
temp=(char*)buffer;
while(count>=1){
temp[--count]=c;
}
temp[count_temp]='\0';
return buffer;
}
void main(){
char buffer[5];
int i=0;
char c='a';
int count=4;
my_memset(buffer,c,4);
for(i=0;i<4;i++){
printf("%c",buffer[i]);
}
}
#include<assert.h>
void *my_memset(void *buffer,char c,int count){
assert(buffer);
char *temp;
int count_temp=count;
temp=(char*)buffer;
while(count>=1){
temp[--count]=c;
}
temp[count_temp]='\0';
return buffer;
}
void main(){
char buffer[5];
int i=0;
char c='a';
int count=4;
my_memset(buffer,c,4);
for(i=0;i<4;i++){
printf("%c",buffer[i]);
}
}

本文详细探讨了C语言中memcpy函数的使用方法、实现原理及常见错误案例,帮助开发者掌握内存复制技巧。
1255

被折叠的 条评论
为什么被折叠?



