gpt4 book ai didi

创建txt文件并从中读取

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

我试图创建 mydata.txt 并从中读取,但编译器给出的结果为

0.0000000.0000001682686832

What is wrong with this code?

int main()
{
double f_1, f_2;
int i_1, i_2;
FILE *file_pointer;
char file_name[SIZE] = "mydata.txt";

file_pointer = fopen(file_name, "w");
fprintf(file_pointer, "%f %f %d %d", 23.556, -76e5, 76, 5);

file_pointer = fopen(file_name, "r");
fscanf(file_pointer, "%lf %lf %ld %ld", &f_1, &f_2, &i_1, &i_2);

fclose(file_pointer);

printf("%f\n", f_1);
printf("%f\n", f_2);
printf("%d\n", i_1);
printf("%d\n", i_2);

getch();

return 0;
}

最佳答案

在第二个fopen()之前执行fclose()

关于创建txt文件并从中读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23276614/

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