ç函数getline跳过空白行 [英] c getline skip blank line

查看:518
本文介绍了ç函数getline跳过空白行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 而(函数getline(安培;线,&安培;!line_size,F)=  -  1){}


  

我使用这个功能来读取行线。但我想,当我在读一个空行就知道了。有人可以帮忙吗?



解决方案

这样H2CO3已经提到的,你可以使用线路长度为这样的:

 而(函数getline(安培;线,&安培; line_size,F)!= -1){    如果(strlen的(线)== 1){
        的printf(H2CO3看准一个空行\\ n);
    }    / *或*交替/
    如果('\\ n'==行[0]){
        的printf(埃德效治疗术也看准空行\\ n);
    }    ..
}

while(getline (&line, &line_size, f) != -1){}  

I'm using this function to read line line. But i want to know when i'm reading a blank line. Can someone help?

解决方案

so as H2CO3 already mentioned you can use the line length for this:

while (getline (&line, &line_size, f) != -1) {

    if (strlen(line) == 1) {
        printf("H2CO3 spotted a blank line\n");
    }

    /* or alternatively */
    if ('\n' == line[0]) {
        printf("Ed Heal also spotted the blank line\n");
    }

    ..
}

这篇关于ç函数getline跳过空白行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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