对于字符串'\0'字符的疑问
本帖最后由 CppOrJava 于 2013-02-03 16:15:24 编辑 我写了一段输出 "Happy New Year!" 的程序.
#include <stdio.h>
#include <string.h>
void swap_char(char *p1, char *p2)
{
char temp;
temp = *p1;
*p1 = *p2;
*p2 = temp;
}
void ch_str1(char *p)
{
int i, j;
for (i = 0, j = strlen(p) - 1; i < j; i += 1, j -= 1)
{
swap_char(p + i, p + j);
}
}
int main(void)
{
char temp[] =
{
0x21, 0x71, 0x5f,
0x62, 0x55, 0x1b,
0x71, 0x5e, 0x46,
0x17, 0x6f, 0x65,
0x64, 0x54, 0x3a,
'\0'
};
int i;
for (i = 0; i < strlen(temp); i += 1)
{
*(temp + i) += i;
}
ch_str1(temp);
printf("%s\n", temp);
return 0;
}