如何检查数组字符串中是否有空格? 你可以帮帮我吗?提前致谢;)
for ( i = 0; string[i] != '\0'; ++i )
if ( string[i]) != ' ' )
error: expected expression
最佳答案
您可以使用标准函数 strchr(string, ' ')
- 如果 string
内部有空格,则返回一个非 NULL 指针:
if(strchr(string, ' '))
{
// printf( "string contain space" );
}
引用strchr
函数:
7.24.5.2 The strchr function
#include <string.h>
char *strchr(const char *s, int c);
3 The strchr function returns a pointer to the located character, or a null pointer if the character does not occur in the string.
关于c - C语言检查数组字符串中是否有空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41649672/