delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/03/16/16:20:36

From: ams AT ludd DOT luth DOT se (Martin Str|mberg)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Strange behaviour
Date: 16 Mar 1999 19:03:29 GMT
Organization: University of Lulea, Sweden
Lines: 45
Message-ID: <7cm9u1$f69$3@news.luth.se>
References: <36ee7e34 DOT 0 AT nnrp1 DOT news DOT uk DOT psi DOT net>
NNTP-Posting-Host: queeg.ludd.luth.se
X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Ya'qub (rick AT nct-active DOT com) wrote:
: Greetings,
:     Sorry for posting this again but the first post didn't get any reply :(
: Can anyone please compile and run the following short program and tell me if
: they can get it to work.
: ----------------------
: #include <stdio.h>
: int main()
: {
:     FILE* infid;
:     FILE* outfid;
: 
:     short val;
: 
:     infid = fopen("output.dat","r");
:     outfid = fopen("result","w");
: 
:     while (fscanf(infid,"%hX",&val) == 1)
:         fprintf(outfid,"%.10f\n",(float)val/32768.0);
: 
:     fclose(infid);
:     fclose(outfid);
: 
:     return 0;
: }
: --------------------------------------------------------
: The file output.dat contains numbers in hex, one per line e.g.
: 0x1234
: 0xF234
: 0x5678
: 
: Whenever I run the program, the 'result' file is always empty. However, the
: same program runs fine when compiled and run from MSVC. Any ideas? Thanks.
: Ya'qub

It seems you have found a bug in MSVC.
Try "while (fscanf(infid," 0x%hX",&val) == 1)".

I havn't tried it but according to my C reference book %x and possibly
%X reads a base 16 number; not 0x followed by a base 16 number.


Shostakovich, String Quartet No. 15,

							MartinS

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019