字符串问题
void *mymemset(char *dest, char c, size_t count)
{
int sum = 0;
for(;*dest != 0;++dest)
{
sum++;
}
if(sum < count)
return 0;
for(int i = 0; i<count;++i)
{
dest[i] = c;
}
}
int main()
{
char array1[] ="sdaffgfgdfdsfdsfdfdfdf";
mymemset(array1,'e', 6);
cout << array1<<endl;
return 0;
}
练习下,但是出错了 //将dest前面count个字符置为字符c. 返回dest的值
请 帮我 看看,谢谢啦
[解决办法]
- C/C++ code
#include<iostream>using namespace std;char *mymemset(char *dest, char c, size_t count){ int sum = 0;char *p=dest;for(;*p!= '\0';++p){sum++;} if(sum < count)return 0;for(int i = 0; i<count;++i){dest[i] = c;}return dest;}int main(){char array1[] ="sdaffgfgdfdsfdsfdfdfdf";mymemset(array1,'e', 6);cout << array1<<endl; system("pause"); return 0;}