getline检查行是否为空格 [英] getline check if line is whitespace

查看:120
本文介绍了getline检查行是否为空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法来检查行是否为空.所以我想检查它是否包含\ r \ n \ t和空格之类的空白.

Is there an easy way to check if a line is empty. So i want to check if it contains any white space such as \r\n\t and spaces.

谢谢

推荐答案

您可以使用

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.

这篇关于getline检查行是否为空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆