Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c中的fscanf无法读取双值_C_Scanf - Fatal编程技术网

c中的fscanf无法读取双值

c中的fscanf无法读取双值,c,scanf,C,Scanf,“%f”格式在和之间的行为不同 对于scanf(和系列),%f读入浮点变量,而不是双精度。如果你想读一个double,那么你需要scanf的%lf格式,尽管它们属于同一个家族,OP询问的是fscanf(),而不是scanf() # include <stdio.h> # include <io.h> # include <stdlib.h> int main(int argc,char *argv[]){ FILE *tfptr; int acc

“%f”
格式在和之间的行为不同


对于
scanf
(和系列)
,%f
读入
浮点
变量,而不是
双精度
。如果你想读一个
double
,那么你需要
scanf
%lf
格式,尽管它们属于同一个家族,OP询问的是
fscanf()
,而不是
scanf()
# include <stdio.h>
# include <io.h>
# include <stdlib.h>
int main(int argc,char *argv[]){
   FILE *tfptr;
    int accno;
    double balance;
    if((tfptr=fopen("trans.dat","w"))==NULL){ //check the file trans.dat existed or not
        printf("cannot open file. \n");
        exit(1);
    }
    fscanf(stdin,"%d%f",&accno,&balance);/* read from keyboard */
    fprintf(tfptr,"%d %f",accno,balance);/* write to file */
    fclose(tfptr); //close the file trans.dat
    if((tfptr=fopen("trans.dat","r"))==NULL){ //check the file trans.dat file existed or not
        printf("cannot open file. \n");
        exit(1);
    }
    fscanf(tfptr,"%d%f",&accno,&balance);/* read from file  */
    fprintf(stdout,"%d %f",accno,balance);/* write to screen */
    return 0;
}
12  2.3
12   0.000000
--------------------------------
Process exited with return value 0
Press any key to continue . . .