#include "stdafx.h"
#include "iostream"
#include "assert.h" using namespace std; char* mystrncpy(char* dest, const char* src, int n)
{
assert(dest!=NULL && src!=NULL);
int count = ;
while (*src != '\0')
{
if (count >= n)
{
break;
}
dest[count++] = *src++;
}
dest[count] = '\0';
return dest;
} int main(int argc, char* argv[])
{
printf("Hello World!\n");
char buf[] = {};
mystrncpy(buf, "FUCK!", );
cout << buf << endl;
return ;
}
输出:
Hello World!
FUCK!
Press any key to continue