[liuqiang@a2 string]$ cat stringTest.c
#include<stdio.h>
#include<string.h>
int main()
{
char s[]="Njupt";
// s[2]=0;
printf("%lu %s",strlen(s),s);
return 0;
}
结果:
[liuqiang@a2 string]$ gcc -o stringTest stringTest.c
[liuqiang@a2 string]$ ./stringTest
5 Njupt
[liuqiang@a2 string]$ cat stringTest.c
#include<stdio.h>
#include<string.h>
int main()
{
char s[]="Njupt";
s[2]=0; //效果相当于结束标示符‘\0’:
printf("%lu %s",strlen(s),s);
return 0;
}
[liuqiang@a2 string]$ gcc -o stringTest stringTest.c
[liuqiang@a2 string]$ ./stringTest
2 Nj