www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/08/31/22:17:33

Xref: news2.mv.net comp.os.msdos.djgpp:8121
From: "Luis A. Salazar" <luiss AT lonestar DOT jpl DOT utsa DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Scanf doesn't work
Date: Sat, 31 Aug 1996 16:46:17 -0500
Organization: The University of Texas at San Antonio
Lines: 31
Message-ID: <Pine.SOL.3.91.960831161714.9065A-100000@lonestar.jpl.utsa.edu>
References: <01bb974a$24b5f820$24c5b7c7 AT platko DOT ix DOT netcom DOT com>
NNTP-Posting-Host: lonestar.jpl.utsa.edu
Mime-Version: 1.0
In-Reply-To: <01bb974a$24b5f820$24c5b7c7@platko.ix.netcom.com>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

 

On 31 Aug 1996, Bob Platko wrote:

> Anyone been having problems with scanf?
> 
> When using multiple scanf's in a program, only the input from the last
> scanf is saved
> in the varible.
> 
> My code works fine in Borland, but not in DJGPP!  What's wrong?
> 

The formatting code that is used when reading an unsigned short with 
scanf is %hu. When printing an unsigned short with printf you should use 
%u. The foregoing can best be exemplified with the following short program:


#include <stdio.h>

main()
{
   unsigned short k, j;

   printf("Enter two numbers");
   scanf("%hu", &k);
   scanf("%hu", &j);
   printf("\n\n");
   printf("%u\n%u", k, j);
   return 0;
}   

- Raw text -


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