By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,470 Members | 1,482 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,470 IT Pros & Developers. It's quick & easy.

scan: which format for a long long int

P: n/a
Which format I have to use in scanf,
to format a long long int (64bits int
__int64 in MS VC++).
Thanks in advance
Nov 15 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
__frank__ <no***********@indirizzo.non.valido> writes:
Which format I have to use in scanf,
to format a long long int (64bits int
__int64 in MS VC++).


"%lld", if your library supports it. It's required by C99, but of
course there was long long type in C90.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #2

P: n/a
__frank__ wrote:
Which format I have to use in scanf,
to format a long long int (64bits int
__int64 in MS VC++).
Thanks in advance


"%lld" or "%lli".

Note: The long long integer types are in the language since C99;
AFAIK, MS VC will not fully support C99 even in their 2005 Studio.
At least in VC++6, the semantics of the 64 bit types were partially
broken.
If the above format does not work, you have a 64 bit type as an
implementation specific extension; the format should be specified
in the online help. Otherwise, you may have to ask in a newsgroup
or forum where your implementation is topical.

BTW: If you try to keep your code conforming, you can #define
the appropriate integer conversion format strings and work with
them like that:

#if (defined __STDC_VERSION__) && __STDC_VERSION__ >= 199901L
# define MY_SLLFORMAT "%lld"
# define MY_ULLFORMAT "%llu"
#elif ...... /* ask for your implementation */
...../* Define your implementation specific MY_SLLFORMAT etc here */
#else
# error Cannot define an appropriate 64 bit integer format
#end

.....
printf("Tit (" MY_SLLFORMAT ") for tat\n", mylonglongvar);
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 15 '05 #3

P: n/a
Keith Thompson wrote:
__frank__ <no***********@indirizzo.non.valido> writes:
Which format I have to use in scanf,
to format a long long int (64bits int
__int64 in MS VC++).

"%lld", if your library supports it. It's required by C99, but of
course there was long long type in C90.

^
no

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 15 '05 #4

P: n/a
Michael Mair <Mi**********@invalid.invalid> writes:
Keith Thompson wrote:
__frank__ <no***********@indirizzo.non.valido> writes:
Which format I have to use in scanf,
to format a long long int (64bits int
__int64 in MS VC++).

"%lld", if your library supports it. It's required by C99, but of
course there was long long type in C90.

^
no


Whoops! Thanks.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #5

P: n/a
On 2005-10-29, Michael Mair <Mi**********@invalid.invalid> wrote:
__frank__ wrote:
Which format I have to use in scanf,
to format a long long int (64bits int
__int64 in MS VC++).
Thanks in advance


"%lld" or "%lli".

Note: The long long integer types are in the language since C99;
AFAIK, MS VC will not fully support C99 even in their 2005 Studio.
At least in VC++6, the semantics of the 64 bit types were partially
broken.
If the above format does not work, you have a 64 bit type as an
implementation specific extension; the format should be specified
in the online help. Otherwise, you may have to ask in a newsgroup
or forum where your implementation is topical.

BTW: If you try to keep your code conforming, you can #define
the appropriate integer conversion format strings and work with
them like that:

#if (defined __STDC_VERSION__) && __STDC_VERSION__ >= 199901L
# define MY_SLLFORMAT "%lld"
# define MY_ULLFORMAT "%llu"
#elif ...... /* ask for your implementation */
..../* Define your implementation specific MY_SLLFORMAT etc here */
#else
# error Cannot define an appropriate 64 bit integer format
#end

....
printf("Tit (" MY_SLLFORMAT ") for tat\n", mylonglongvar);
Cheers
Michael


Usually when defining a macro for a format specifier you don't want
to include the % sign, so as to allow the user to include field
widths and so on

for example

#define PRIdLLONG "lld"
#define PRIuLLONG "llu"

printf("Here's an example with a field width: %10"PRIdLLONG"\n", var);
[i don't know if the entire PRI*/SCN* set of identifiers are
reserved if inttypes.h is included - however if his system has
inttypes.h he should probably be using the types defined therein
instead]
Nov 15 '05 #6

P: n/a
__frank__ 写道:
Which format I have to use in scanf,
to format a long long int (64bits int
__int64 in MS VC++).
Thanks in advance

In MS VC++, '__int64' read by this way
__int64 i;
scanf("%I64d", &i);

Nov 15 '05 #7

P: n/a
"kaikai" <zi********@gmail.com> writes:
__frank__ 写道:
Which format I have to use in scanf,
to format a long long int (64bits int
__int64 in MS VC++).
Thanks in advance

In MS VC++, '__int64' read by this way
__int64 i;
scanf("%I64d", &i);


And *only* (as far as I know) in MS VC++. "%I64d" is non-standard and
non-portable. Writing non-portable code is sometimes necessary, of
course.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #8

P: n/a
Jordan Abel wrote:
On 2005-10-29, Michael Mair <Mi**********@invalid.invalid> wrote:
__frank__ wrote:
Which format I have to use in scanf,
to format a long long int (64bits int
__int64 in MS VC++).
Thanks in advance


"%lld" or "%lli".

Note: The long long integer types are in the language since C99;
AFAIK, MS VC will not fully support C99 even in their 2005 Studio.
At least in VC++6, the semantics of the 64 bit types were partially
broken.
If the above format does not work, you have a 64 bit type as an
implementation specific extension; the format should be specified
in the online help. Otherwise, you may have to ask in a newsgroup
or forum where your implementation is topical.

BTW: If you try to keep your code conforming, you can #define
the appropriate integer conversion format strings and work with
them like that:

#if (defined __STDC_VERSION__) && __STDC_VERSION__ >= 199901L
# define MY_SLLFORMAT "%lld"
# define MY_ULLFORMAT "%llu"
#elif ...... /* ask for your implementation */
..../* Define your implementation specific MY_SLLFORMAT etc here */
#else
# error Cannot define an appropriate 64 bit integer format
#end

....
printf("Tit (" MY_SLLFORMAT ") for tat\n", mylonglongvar);


Usually when defining a macro for a format specifier you don't want
to include the % sign, so as to allow the user to include field
widths and so on

for example

#define PRIdLLONG "lld"
#define PRIuLLONG "llu"

printf("Here's an example with a field width: %10"PRIdLLONG"\n", var);


Thank you -- I did not think of this at that moment

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 15 '05 #9

P: n/a
Keith Thompson wrote:
"kaikai" <zi********@gmail.com> writes:
__frank__ 写道:
Which format I have to use in scanf,
to format a long long int (64bits int
__int64 in MS VC++).
Thanks in advance

In MS VC++, '__int64' read by this way
__int64 i;
scanf("%I64d", &i);


And *only* (as far as I know) in MS VC++. "%I64d" is non-standard and
non-portable. Writing non-portable code is sometimes necessary, of
course.


It is also supported by WATCOM C/C++, Borland C, and the Alpha
compiler. This, presumably, is why C99 included stdint.h, and
inttypes.h which includes abstractions for all these things.

The only problem, of course, is that nobody seriously supports C99. So
as a stop gap, you can use pstdint.h available here:

http://www.pobox.com/~qed/pstdint.h

This file can be used by older compilers that don't have even partial
support for C99, and possible don't support 64 bit integers at all (you
can test for this with a #ifdef INT64_MAX in your code.)

This file includes a slightly different abstraction for print modifiers
than inttypes.h -> The macro PRINTF_INT64_MODIFIER is used to specify
the 64bit prefix for the integer formats. So:

"%" PRINTF_INT64_MODIFIER "d"

is (usually) the same as "%lld" or "%I64d" depending on which compiler
you are using.

--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/

Nov 15 '05 #10

P: n/a
Jordan Abel a crit :
Usually when defining a macro for a format specifier you don't want
to include the % sign, so as to allow the user to include field
widths and so on


Good point. Well noted.

--
C is a sharp tool
Nov 15 '05 #11

P: n/a
Keith Thompson a écrit :
And *only* (as far as I know) in MS VC++. "%I64d" is non-standard and
non-portable. Writing non-portable code is sometimes necessary, of
course.


The question is not about the compiler or the IDE, but about the
library. If your linker uses a library that loads the MSVCRT DLL, you
are cooked. (VC++6, of course, but also Dev-C++ and more generally mingw
based IDEs)

--
C is a sharp tool
Nov 15 '05 #12

P: n/a
On Sat, 29 Oct 2005 09:51:23 +0000 (UTC), Jordan Abel
<jm****@purdue.edu> wrote:
<snip>
BTW: If you try to keep your code conforming, you can #define
the appropriate integer conversion format strings and work with
them like that:

#if (defined __STDC_VERSION__) && __STDC_VERSION__ >= 199901L
# define MY_SLLFORMAT "%lld"
# define MY_ULLFORMAT "%llu"
#elif ...... /* ask for your implementation */
..../* Define your implementation specific MY_SLLFORMAT etc here */
#else
# error Cannot define an appropriate 64 bit integer format
#end
Usually when defining a macro for a format specifier you don't want
to include the % sign, so as to allow the user to include field
widths and so on

for example

#define PRIdLLONG "lld"
#define PRIuLLONG "llu"

printf("Here's an example with a field width: %10"PRIdLLONG"\n", var);
[i don't know if the entire PRI*/SCN* set of identifiers are
reserved if inttypes.h is included - however if his system has
inttypes.h he should probably be using the types defined therein
instead]


They ({PRI,SCN}[a-zX].*) are; 7.26.4.

- David.Thompson1 at worldnet.att.net
Nov 15 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.