char str[50];
char strToCopy[16];
int numberOfBytesToFill = 7; // fills 1st n bytes of the memory area pointed to
char charToFillInAs = '*'; //48: ascii for '0' // '$';
void* targetStartAddress = str;
strncpy(strToCopy, "tO sEe The wOrLd", strlen("tO sEe The wOrLd")+1);
puts(strToCopy); // print
strcpy(str, "Test statement !@#$%^&*()=+_~```::||{}[]");
puts(str); // print
memset(targetStartAddress, charToFillInAs, numberOfBytesToFill); // fill memory with a constant byte (ie. charToFillInAs)
puts(str); // print
memcpy(targetStartAddress, strToCopy, strlen(strToCopy)+1); // +1 for null char
puts(str); // print
输出是:
tO sEe The wOrLd
Test statement !@#$%^&*()=+_~```::||{}[]
*******atement !@#$%^&*()=+_~```::||{}[]
tO sEe The wOrLd*******atement !@#$%^&*()=+_~```::||{}[]
因此,我的问题是为什么
tO sEe The wOrLd*******atement !@#$%^&*()=+_~```::||{}[]
代替
tO sEe The wOrLd\0#$%^&*()=+_~```::||{}[]
作为'\0'
空字符?