更新时间:2023-11-29 15:26:04
You can use the isspace
function in a loop to check if all characters are whitespace:
int is_empty(const char *s) {
while (*s != '\0') {
if (!isspace((unsigned char)*s))
return 0;
s++;
}
return 1;
}
如果任何字符不是空格(即行不为空),则此函数将返回0,否则返回1.
This function will return 0 if any character is not whitespace (i.e. line is not empty), or 1 otherwise.