无法读取C中的EOF字符 [英] unable to read the EOF character in C

查看:95
本文介绍了无法读取C中的EOF字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在读取C中最后一个输入的EOF字符时有问题

I have a problem with reading the EOF character for the last input in C

j=0;       
while(*(name2+j)!='\n'){
    if(*(name2+j) == ' '){
        j++;
        continue;
    }
    d[tolower(*(name2+j))]++;
    j++;
}

对于最后一个输入,没有换行符,j的值对于非常小的字符串,设置为非常大的数字。因此,考虑文件的结尾,我将while条件修改为

For the last input, there is no new line character, the value of j is getting set to very large number for a very small string. So, to consider the end of file, i modified the while condition to

while(*(name2+j)!='\n' && (*(name2+j))!=EOF)

但是我仍然有同样的问题。有人可以告诉我我在这里想念什么吗?谢谢。

but still i am having the same problem. Can someone tell if i am missing something here ? Thanks.

推荐答案

EOF 是超出a范围的整数值 char (因为它的主要目的是表明存在 no char ),因此如果您希望能够将值与 EOF 进行比较,则需要检索该值并将其存储为 int ,而不是作为 char

EOF is an integer value outside the range of a char (since its very purpose is to indicate that no char is present), so if you want to be able to compare a value to EOF, then you need to retrieve and store that value as an int rather than as a char.

这篇关于无法读取C中的EOF字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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