我用 strrchr 得到了一些奇怪的结果。请帮我。
这是我的代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char szString[32] = "hello-world-and-everyone";
char* ptemp = NULL;
ptemp = strrchr(szString, '-');
if (ptemp == NULL)
{
printf("Invalid string\n");
return 1;
}
printf("%s\n", szString);
printf("%s\n", ptemp );
*ptemp = 0;
printf("%s\n", szString);
return 0;
}
预期结果:
hello-world-and-everyone
-everyone
hello-world-and-everyone
实际结果:
hello-world-and-everyone
-everyone
hello-world-and