且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

getline检查行是否为空格

更新时间: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.