gpt4 book ai didi

c - 从文件读取时出现错误

转载 作者:行者123 更新时间:2023-11-30 20:40:37 25 4
gpt4 key购买 nike

每当我尝试从文件中读取字符并尝试访问它时,我都会收到错误。我的代码是:

while((c=fgetc(f))!=EOF) {
if(c == '\n') {
str[i]='\0';

Info* inf = new Info();
inf->getInputFromFile(str);
if((table->insert(inf))==0)
cout<<"exist."<<endl;
//delete inf;

for(int j =0; j<50;j++)
str[j]='\0';

i=0;

} else {
str[i] = c;
i++;
}

但是在这里,每当我尝试给出一个虚拟单词时,例如:inf->getInputFromFile("Hello");我没有收到任何错误。我也无法使用 debuggin 找到错误,因为当我按 F8(CodeBlocks IDE)时,我的调试器启动并且它不会停止任何行。即使用 F8 运行程序时我没有发现任何错误。

这是输入文件内容:

int, INTEGER
myFunction, FUNCTION
x, IDENTIFIER
5, NUMBER
x, Identity
char, CHARACTER
fl, FLOAT
dbl, DOUBLE
you, MEINTHIS
dlt, DELETE
hel, HELLOWORLD
string, STRING

最佳答案

这里回答了如何用 C 读取文件:In C, how should I read a text file and print all strings我认为这就是您正在寻找的答案。

关于c - 从文件读取时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21368290/

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