我看到人们最近在很多帖子中试图读取这样的文件.
码
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char **argv)
{
char *path = argc > 1 ? argv[1] : "input.txt";
FILE *fp = fopen(path, "r");
if( fp == NULL ) {
perror(path);
return EXIT_FAILURE;
}
while( !feof(fp) ) { /* THIS IS WRONG */
/* Read and process data from file… */
}
if( fclose(fp) == 0 ) {
return EXIT_SUCCESS;
} else {
perror(path);
return EXIT_FAILURE;
}
}
Run Code Online (Sandbox Code Playgroud)
这个__CODE__循环有什么问题?
我一直绊倒printf()函数系列的格式说明符.我想要的是能够在小数点后打印一个最大给定位数的double(或float).如果我使用:
printf("%1.3f", 359.01335);
printf("%1.3f", 359.00999);
Run Code Online (Sandbox Code Playgroud)
我明白了
359.013
359.010
Run Code Online (Sandbox Code Playgroud)
而不是期望的
359.013
359.01
Run Code Online (Sandbox Code Playgroud)
有谁能够帮我?