From: Bao C. H. <ba...@se...> - 2001-08-13 18:33:50
|
I am having problems with the following code. It works fine in an x86 system. The problem is at the minus sign of the datum. The scanf is doing something weird. Changing "%f" to "%lf" in the scanf statement makes it work again. ==== test.c ===== [bao@build bao]$ cat test.c #include <inttypes.h> #include <stdio.h> #include <stdlib.h> int main() { FILE *fptr; float dum; int status; fptr=fopen("./DATA", "r"); while (!feof(fptr)){ status = fscanf(fptr,"%f", &dum); printf("\n status=%x\n", (int)status); if (status) printf("\n dum=%f\n", dum); } } [bao@build bao]$ sh4-linux-gcc test.c -o test === Output of test === [root@mgatebao /root]# ./test status=1 dum=0.000000 status=1 dum=0.951057 status=1 dum=0.587785 status=%x dum=%f |AGNUÿÿÿÿÿÿÿÿ¨A¼@Ø@ô@@,@H@d@M¬ À@ä@D@ @@ ± ATÔ@þÿÿo´@ÿÿÿoðÿÿo @GCC: (GNU) 2.97 20001120 (experimental)GCC: (GNU) 2.97 200 01120 (experimental)GCC: (GNU) 2.97 20001120 (experimental)GCC: (GNU) 2.97 20001 120 (experimental)GCC: (GNU) 2.97 20001120 (experimental)GCC: (GNU) 2.97 2000112 0 (experimental).symtab.strtab.shstrtab.interp.hash.dynsym.dynstr.gnu.version. gn u.version_r.rela.plt.init.plt.text.fini.rodata.data.note.ABI-tag.ctors.dtors .got .dynamic.sbss.bss.commentô<) D@D 1ä@ä»9ÿÿÿo @ Fþÿÿo´@´ UÔ@ÔT _@@@V e@àj@@ @LÀ@À6 v0§ô@D@ä@ @´@Ô@@@xA A@¨A¨®AA¹öF Âð À@ ø@ PApAxAA¨AAAñÿAñÿñÿñÿñÿñÿñÿʰ@ Segmentation fault === Input: DATA === [root@mgatebao /root]# cat DATA 0.0000000e+000 9.5105652e-001 +5.8778525e-001 -9.5105652e-001 ================== Appreciate any suggestions/comments. Thanks. Bao |