我很难理解这部分意味着什么:
if (!s || !*s) //What is this?!?!
{
printf("\n");
return;
}
Run Code Online (Sandbox Code Playgroud)
这是我的主要功能:
#include <conio.h>
#include <stdio.h>
#include <string.h>
void func1(char *s);
int main()
{
func1("SABABA");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
而我的func1:
void func1(char *s)
{
int a, b, c;
if (!s || !*s)
{
printf("\n");
return;
}
b = strlen(s);
while (b>2)
{
a = 0;
if (s[a] == s[b - 1])
{
for (c = b - 1; c >= a && s[a] == s[c]; a++, c--);
if (c<a)
{
int i;
for (i = 0; i<b; i++)
printf("%c", s[i]);
printf(" ");
}
}
b--;
}
func1(s + 1);
}
Run Code Online (Sandbox Code Playgroud)
我的观点: 's'代表字符串的地址,而s表示当我们在字符串的"堆栈"之外时.例如,如果起始地址是1000并且字符串是6个字符,我们最终在1006.如果我们超过1006,例如到1007那么它!s返回true.并且关于*s,它检查地址1000持有的值,即"S",这是真的,意思是!*s是假的.并且因为我们知道每个字符串以"/ 0"结尾,我想在1007,我们搜索它.如果我是对的,那么为什么我们需要两个!s和*s,为什么不只是其中之一.我能做到这一点吗?
!s检查s不是空指针.
!*s检查s指向的char 是不是'\0',这意味着s不是空字符串.
该检查与调用不匹配func1("SABABA"),但是为func1(0)或等准备func1("").