Closed. This question is off-topic。它当前不接受答案。
想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
3年前关闭。
我想从文件中读取文件,并通过修改代码将其保存到另一个文件中。
输入文件为:
我得到的输出是:
全零。为什么?
想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
3年前关闭。
#include<stdio.h>
#include<stdlib.h>
#include<io.h>
#include<conio.h>
extern _floatconvert;
#pragma extref _floatconvert
void main()
{
FILE *in,*out;
double f;
in = fopen("A.txt","r");
out = fopen("S.txt","w");
for (int i=0;i<18;i++)
{
for (int j=0;j<18;j++)
{
fscanf(in,"%.15lf",&f);
fprintf(stdout,"%.15lf",f);
getch();
fprintf(out,"A=[%d][%d] = %lf ;",i,j,f);
}
}
fclose(in);
fclose(out);
getch();
}
我想从文件中读取文件,并通过修改代码将其保存到另一个文件中。
输入文件为:
3.53448000000 -4.77154800002 1.76724000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 -4.77154800002 1.71775730005 0.00000000000 -8.58878640004 4.77154800002 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 1.76724000000 0.00000000000 7.06896000000 -4.77154800002 1.76724000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 -8.58878640004 4.77154800002 1.71775730005 0.00000000000 -8.58878640004 4.77154800002 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 4.77154800002 1.76724000000 0.00000000000 7.06896000000 -4.77154800002 1.76724000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 -8.58878640004 -4.77154800002 1.71775730005 0.00000000000 -8.58878640004 4.77154800002 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 4.77154800002 1.76724000000 0.00000000000 7.06896000000 -4.77154800002 1.76724000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 -8.58878640004 -4.77154800002 1.71775730005 0.00000000000 8.58878640004 4.77154800002 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 4.77154800002 1.76724000000 0.00000000000 7.06896000000 -4.77154800002 1.76724000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 8.58878640004 -4.77154800002 1.71775730005 0.00000000000 -8.58878640004 4.77154800002 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 4.77154800002 1.76724000000 0.00000000000 7.06896000000 4.77154800002 1.76724000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 -8.58878640004 -4.77154800002 1.71775730005 0.00000000000 -8.58878640004 4.77154800002 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 4.77154800002 1.76724000000 0.00000000000 7.06896000000 -4.77154800002 1.76724000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 -8.58878640004 -4.77154800002 1.71775730005 0.00000000000 -8.58878640004 4.77154800002 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 4.77154800002 1.76724000000 0.00000000000 7.06896000000 -4.77154800002 1.76724000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 -8.58878640004 -4.77154800002 1.71775730005 0.00000000000 4.77154800002 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 4.77154800002 1.76724000000 0.00000000000 7.06896000000 1.76724000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 0.00000000000 4.77154800002 1.76724000000 3.53448000000
我得到的输出是:
A=[0][0] = -0.000000 ;A=[0][1] = -0.000000 ;A=[0][2] = -0.000000 ;A=[0][3] = -0.000000 ;A=[0][4] = -0.000000 ;A=[0][5] = -0.000000 ;A=[0][6] = -0.000000 ;A=[0][7] = -0.000000 ;A=[0][8] = -0.000000 ;A=[0][9] = -0.000000 ;A=[0][10] = -0.000000 ;A=[0][11] = -0.000000 ;A=[0][12] = -0.000000 ;A=[0][13] = -0.000000 ;A=[0][14] = -0.000000 ;A=[0][15] = -0.000000 ;A=[0][16] = -0.000000 ;A=[0][17] = -0.000000 ;A=[1][0] = -0.000000 ;A=[1][1] = -0.000000 ;A=[1][2] = -0.000000 ;A=[1][3] = -0.000000 ;A=[1][4] = -0.000000 ;A=[1][5] = -0.000000 ;A=[1][6] = -0.000000 ;A=[1][7] = -0.000000 ;A=[1][8] = -0.000000 ;A=[1][9] = -0.000000 ;A=[1][10] = -0.000000 ;A=[1][11] = -0.000000 ;A=[1][12] = -0.000000 ;A=[1][13] = -0.000000 ;A=[1][14] = -0.000000 ;A=[1][15] = -0.000000 ;A=[1][16] = -0.000000 ;A=[1][17] = -0.000000 ;A=[2][0] = -0.000000 ;A=[2][1] = -0.000000 ;A=[2][2] = -0.000000 ;A=[2][3] = -0.000000 ;A=[2][4] = -0.000000 ;A=[2][5] = -0.000000 ;A=[2][6] = -0.000000 ;A=[2][7] = -0.000000 ;A=[2][8] = -0.000000 ;A=[2][9] = -0.000000 ;A=[2][10] = -0.000000 ;A=[2][11] = -0.000000 ;A=[2][12] = -0.000000 ;A=[2][13] = -0.000000 ;A=[2][14] = -0.000000 ;A=[2][15] = -0.000000 ;A=[2][16] = -0.000000 ;A=[2][17] = -0.000000 ;A=[3][0] = -0.000000 ;A=[3][1] = -0.000000 ;A=[3][2] = -0.000000 ;A=[3][3] = -0.000000 ;A=[3][4] = -0.000000 ;A=[3][5] = -0.000000 ;A=[3][6] = -0.000000 ;A=[3][7] = -0.000000 ;A=[3][8] = -0.000000 ;A=[3][9] = -0.000000 ;A=[3][10] = -0.000000 ;A=[3][11] = -0.000000 ;A=[3][12] = -0.000000 ;A=[3][13] = -0.000000 ;A=[3][14] = -0.000000 ;A=[3][15] = -0.000000 ;A=[3][16] = -0.000000 ;A=[3][17] = -0.000000 ;A=[4][0] = -0.000000 ;A=[4][1] = -0.000000 ;A=[4][2] = -0.000000 ;A=[4][3] = -0.000000 ;A=[4][4] = -0.000000 ;A=[4][5] = -0.000000 ;A=[4][6] = -0.000000 ;A=[4][7] = -0.000000 ;A=[4][8] = -0.000000 ;A=[4][9] = -0.000000 ;A=[4][10] = -0.000000 ;A=[4][11] = -0.000000 ;A=[4][12] = -0.000000 ;A=[4][13] = -0.000000 ;A=[4][14] = -0.000000 ;A=[4][15] = -0.000000 ;A=[4][16] = -0.000000 ;A=[4][17] = -0.000000 ;A=[5][0] = -0.000000 ;A=[5][1] = -0.000000 ;A=[5][2] = -0.000000 ;A=[5][3] = -0.000000 ;A=[5][4] = -0.000000 ;A=[5][5] = -0.000000 ;A=[5][6] = -0.000000 ;A=[5][7] = -0.000000 ;A=[5][8] = -0.000000 ;A=[5][9] = -0.000000 ;A=[5][10] = -0.000000 ;A=[5][11] = -0.000000 ;A=[5][12] = -0.000000 ;A=[5][13] = -0.000000 ;A=[5][14] = -0.000000 ;A=[5][15] = -0.000000 ;A=[5][16] = -0.000000 ;A=[5][17] = -0.000000 ;A=[6][0] = -0.000000 ;A=[6][1] = -0.000000 ;A=[6][2] = -0.000000 ;A=[6][3] = -0.000000 ;A=[6][4] = -0.000000 ;A=[6][5] = -0.000000 ;A=[6][6] = -0.000000 ;A=[6][7] = -0.000000 ;A=[6][8] = -0.000000 ;A=[6][9] = -0.000000 ;A=[6][10] = -0.000000 ;A=[6][11] = -0.000000 ;A=[6][12] = -0.000000 ;A=[6][13] = -0.000000 ;A=[6][14] = -0.000000 ;A=[6][15] = -0.000000 ;A=[6][16] = -0.000000 ;A=[6][17] = -0.000000 ;A=[7][0] = -0.000000 ;A=[7][1] = -0.000000 ;A=[7][2] = -0.000000 ;A=[7][3] = -0.000000 ;A=[7][4] = -0.000000 ;A=[7][5] = -0.000000 ;A=[7][6] = -0.000000 ;A=[7][7] = -0.000000 ;A=[7][8] = -0.000000 ;A=[7][9] = -0.000000 ;A=[7][10] = -0.000000 ;A=[7][11] = -0.000000 ;A=[7][12] = -0.000000 ;A=[7][13] = -0.000000 ;A=[7][14] = -0.000000 ;A=[7][15] = -0.000000 ;A=[7][16] = -0.000000 ;A=[7][17] = -0.000000 ; ... .. .
全零。为什么?
最佳答案
您为fscanf
函数指定了错误的格式说明符。扫描时无需指定精度,因此应写fscanf(in,"%.15lf",&f);
而不是写fscanf(in,"%lf",&f);
09-29 23:59