gpt4 book ai didi

与 fgetc() 和 ungetc() 相关的 C 语法

转载 作者:太空宇宙 更新时间:2023-11-04 08:23:02 25 4
gpt4 key购买 nike

在我的代码中,我试图完成这样的事情(用伪代码编写):

While not at EOF:
Get line
Write line to different file
Skip 30 bytes

目前,我能想到的最好的方法是这样的:

int c;
while((c = fgetc(stream)) != EOF){
ungetc(c,stream);
REST OF CODE

有没有更好的方法来检查我是否在 EOF 但仍然使用我当前正在阅读的字符?

最佳答案

您可能希望在循环外有条件地调用 fgetc:

int c = fgetc(stream);
while(c != EOF){
....
c = fgetc(stream);
}

关于与 fgetc() 和 ungetc() 相关的 C 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32531921/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com