【发布时间】:2015-09-02 06:27:26
【问题描述】:
我试过这个:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
FILE *txt1;
char tam[13];
char tam1[13];
char tam2[13];
txt1 = fopen("C:/Users/Hugo/Documents/C/in2.txt","r");
if(txt1 == NULL)
{
printf("No se puede leer el archivo");
return 0;
}
fgets(tam1,sizeof(tam1), txt1);
double c = atof(tam1);
printf("%f",c);
当我调试时:tam1 is "3.1415926535" 但它会打印:
0.000000
【问题讨论】:
-
您的意思是
printftam1,还是c? -
改用
fscanf(txt1, "%lf", &c)。 -
@nneonneo 没用
-
我不知道出了什么问题。您的代码看起来基本正确,除非您的文件包含一些奇怪的字符或其他内容。
-
是的,它是这样的......我修好了谢谢!
标签: c printf double fgets atof