format specifier

R

Ravi Uday

HI,

What does these mean -

- " lx%08lx "
- " %1024[^\n]%*[^\n] "

I have seen them being used in printfs. When do you exactly write/use these ?

Thx in advance
- Ravi
 
I

Ivan Vecerina

| What does these mean -
|
| - " lx%08lx "

In a printf call:
- the leading lx will be written literally (as is).
- %08lx will print 8 hexadecimal digits with leading zeroes.

| - " %1024[^\n]%*[^\n] "

This looks like it belongs in a scanf call:
- up to the following 1024 characters that do not match the newline
character will be read into the char buffer passed as a parameter.
All the following character up to the newline character are
discarded.

.... if I'm not mistaken.

| I have seen them being used in printfs.
| When do you exactly write/use these ?

When you are sure that all the potential readers of your code
understand the C format specifiers in depth.

A lot can be done with C format specifiers (and even more than
before in the C99 standard). They allow concise parsing of
input and formatting of output text. But they tend to be
tricky and error prone...


Cheers,
 
D

Dan Pop

In said:
| I have seen them being used in printfs.
| When do you exactly write/use these ?

When you are sure that all the potential readers of your code
understand the C format specifiers in depth.

Which means never, considering the impossibility of acquiring such a
certitude ;-)

printf/scanf are basic features of the C language. Whoever deals with a
piece of production code is supposed to be familiar with them.

It makes no sense to avoid such features *only* because an incompetent
programmer might end up reading your code.

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top