晚上好,我有2个函数,每个函数都接受一个指向char的指针作为参数:
char pointer[255];
func1(char* pointer)
{
...
memcpy(pointer,some_char,strlen(something));
return;
}
func2(char* pointer)
{
...
if (pointer==someother_char) exit(0); //FAILs
//also I have
if(pointer==someother_pointer2char); // FAILs
}
Run Code Online (Sandbox Code Playgroud)
现在我尝试了strstr,strcmp等......不起作用.想尝试memcmp,但我没有静态len.因为我必须将char*与char和char*比较为char*我需要两个解决方案吗?
那么,如何以最短的方式比较这些指针(实际上是指针)?
谢谢.
编辑
感谢wallacer和Code Monkey现在用于char*to char比较我使用以下:
func1(char* ptr){
char someother_char[255];
char *ptr_char = NULL; //I have to strcmp a few values so this is why I initialize it first
...
ptr_char = someother_char;
if (strcmp(ptr,ptr_char) == 0) //gtfo and it does...
...
ptr_char = some2nd;
if(strcmp... …Run Code Online (Sandbox Code Playgroud)