473,385 Members | 1,409 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,385 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 20256
__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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.