Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > printf / sscanf unsigned long long int variables

Reply
Thread Tools

printf / sscanf unsigned long long int variables

 
 
Joerg Schwerdtfeger
Guest
Posts: n/a
 
      04-02-2004
Hi everyone,

I want to input & output an unsigned long long int variable, but
printf/sscanf seems to interpret the least significant 32 bits only.

I assume this is a bloody newbie-question, but reading the clc-faq and
googleing for this issue, I only found out that this might be a known
problem - but how can I fix it? Are there any workarounds, e.g. other
io-routines who can handle ull-ints?

Thanks in advance,
Joerg

 
Reply With Quote
 
 
 
 
John Tsiombikas (Nuclear / the Lab)
Guest
Posts: n/a
 
      04-02-2004
Joerg Schwerdtfeger wrote:
> Hi everyone,
>
> I want to input & output an unsigned long long int variable, but
> printf/sscanf seems to interpret the least significant 32 bits only.


use the %llu format specifier for unsigned long longs

--
John Tsiombikas (Nuclear / the Lab)
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://thelab.demoscene.gr/nuclear/
 
Reply With Quote
 
 
 
 
Vijay Kumar R Zanvar
Guest
Posts: n/a
 
      04-02-2004

"Joerg Schwerdtfeger" <(E-Mail Removed)> wrote in message news:c4inin$a7t$05$(E-Mail Removed)-online.com...
> Hi everyone,
>
> I want to input & output an unsigned long long int variable, but
> printf/sscanf seems to interpret the least significant 32 bits only.


Does your compiler support ULLs?

>
> I assume this is a bloody newbie-question, but reading the clc-faq and
> googleing for this issue, I only found out that this might be a known
> problem - but how can I fix it? Are there any workarounds, e.g. other
> io-routines who can handle ull-ints?
>
> Thanks in advance,
> Joerg
>


F:\Vijay\C> type ull.c
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int
main ( void )
{
unsigned long long int ull;
printf ( "ULLONG_MAX: %llu\n", ULLONG_MAX );
printf ( "Enter an ull value: " );
scanf ( "%llu", &ull );
printf ( "\nThe ull value is: " );
printf ( "%llu", ull );
return EXIT_SUCCESS;
}

F:\Vijay\C> gcc -std=c99 -Wall
F:\Vijay\C> a.exe
ULLONG_MAX: 18446744073709551615
Enter an ull value: 18446744073709551614
The ull value is: 18446744073709551614



 
Reply With Quote
 
Joerg Schwerdtfeger
Guest
Posts: n/a
 
      04-02-2004
Vijay Kumar R Zanvar wrote:
> scanf ( "%llu", &ull );
> printf ( "%llu", ull );


Damn! I used %ull instead of %llu. *embarrassed*

Thank you so much!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
long long int and sscanf, printf Hans Vlems C Programming 5 09-07-2012 02:20 PM
(int) -> (unsigned) -> (int) or (unsigned) -> (int) -> (unsigned):I'll loose something? pozz C Programming 12 03-20-2011 11:32 PM
Promoting unsigned long int to long int pereges C Programming 112 07-28-2008 05:00 AM
Having compilation error: no match for call to (const __gnu_cxx::hash<long long int>) (const long long int&) veryhotsausage C++ 1 07-04-2008 05:41 PM
Assigning unsigned long to unsigned long long George Marsaglia C Programming 1 07-08-2003 05:16 PM



Advertisments