473,245 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,245 software developers and data experts.

scan: which format for a long long int

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
12 20226
__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
__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
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
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
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
__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
"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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Josiah Carlson | last post by:
Good day everyone, I have produced a patch against the latest CVS to add support for two new formatting characters in the struct module. It is currently an RFE, which I include a link to at the...
3
by: Carlos Moreno | last post by:
I can't find a reasonable explanation for this. I have a table game, with primary key gameid (an int). If I use a where involving gameid and <, or >, or <=, or >=, then I get a sequential...
7
by: Joe Weinstein | last post by:
Hi. Some DBMSes are clever enough not to go to data pages if a knowably constant search criterion is false. Is DB2 among them? thanks, Joe Weinstein at BEA
14
by: L Mehl | last post by:
I tested a FE/BE application developed in A2000 on a A2002 machine and got this message when exiting the app. Clicking the only available button "OK", exits the application, as intended. The FE...
4
by: smshahriar | last post by:
Hi, I want to scan from the following string all the hex numbers and populate an array of integers: 0x27 0x00 0x30 0x00 0x33 0x00 0x36 0x00
6
by: Jack Orenstein | last post by:
Suppose I have a table as follows: testdb=> \d person Table "public.person" Column | Type | Modifiers ------------+-------------------------+----------- id |...
0
MMcCarthy
by: MMcCarthy | last post by:
This is a module that scans for files and folders on a specified path and describe them in comma separated values file in a text format. The information is stored in this file consecutively like:...
0
by: taufik | last post by:
hi... I try to make scan function working and save it in PDF format using vb.net. Right now, I be able to scan but the image that i save in PDF format cannot be open. Can somebody help me to solve...
5
by: asit | last post by:
What is scan code ?? How to know the SCAN Code of a character ???
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.