putting % in printf 
Author Message
 putting % in printf

Hello,
I'm sure this is easier than I think, but how can I use a % sign in the
following statement...

printf("The % of grades is %s",grade)

When I run it it thinks the first % is a variable assignment or whatever....
Thanks for any help
bill



Sun, 06 Apr 2003 03:00:00 GMT  
 putting % in printf
I think you need to at least _look_ at the manual before asking the world.

Jennifer
(who helps those who help themselves)
--

Quote:

> Hello,
> I'm sure this is easier than I think, but how can I use a % sign in the
> following statement...

> printf("The % of grades is %s",grade)

> When I run it it thinks the first % is a variable assignment or whatever....
> Thanks for any help
> bill



Mon, 07 Apr 2003 11:44:24 GMT  
 putting % in printf
printf ("The %% of grades is %s", grade)

should do the trick
cheers

Quote:

> Hello,
> I'm sure this is easier than I think, but how can I use a % sign in the
> following statement...

> printf("The % of grades is %s",grade)

> When I run it it thinks the first % is a variable assignment or whatever....
> Thanks for any help
> bill



Mon, 07 Apr 2003 12:59:51 GMT  
 putting % in printf

Quote:

> Hello,
> I'm sure this is easier than I think, but how can I use a % sign in the
> following statement...

> printf("The % of grades is %s",grade)

> When I run it it thinks the first % is a variable assignment or whatever....
> Thanks for any help
> bill

Use: printf("The \% of grades i %s\n", grade)

-suku.

--
N. Sukumar, Research Associate                 Work Phone: (609)258-0494
Princeton Materials Institute                  Home Phone: (609)683-4912

WWW: http://www.princeton.edu/~nsukumar               *GO BLAZERS*



Mon, 07 Apr 2003 03:00:00 GMT  
 putting % in printf

Quote:


> > I'm sure this is easier than I think, but how can I use a % sign in the
> > following statement...

> > printf("The % of grades is %s",grade)

> > When I run it it thinks the first % is a variable assignment or
> > whatever....

> Use: printf("The \% of grades i %s\n", grade)

What happened when you tested this?

So far, only Jennifer Cross has posted the Right Answer to Bill's
question.

--
Jim Monty

Tempe, Arizona USA



Mon, 07 Apr 2003 03:00:00 GMT  
 putting % in printf
Bill schrieb:

Quote:

> Hello,
> I'm sure this is easier than I think, but how can I use a % sign in the
> following statement...

> printf("The % of grades is %s",grade)

> When I run it it thinks the first % is a variable assignment or whatever....
> Thanks for any help
> bill

Seems that nobody can help you (or wants to).

So, here is a possible answer:

printf("The %s of grades is %s", "%", grade)

Isn't that tricky?

HTH

Dieter

--
Though this is a sick signature, it's still a significant signature.



Tue, 08 Apr 2003 03:00:00 GMT  
 putting % in printf

Quote:

> Bill schrieb:

> > Hello,
> > I'm sure this is easier than I think, but how can I use a % sign in the
> > following statement...

> > printf("The % of grades is %s",grade)

> > When I run it it thinks the first % is a variable assignment or whatever....
> > Thanks for any help
> > bill

> Seems that nobody can help you (or wants to).

> So, here is a possible answer:

> printf("The %s of grades is %s", "%", grade)

> Isn't that tricky?

Does "printf("The %% of grades is %s",grade)" work?

-jp



Tue, 08 Apr 2003 03:00:00 GMT  
 putting % in printf
Jean-Philippe Theberge schrieb:

Quote:

> Does "printf("The %% of grades is %s",grade)" work?

It works for me, it works for you and perhaps it even works for Bill.

But it seems that it doesn't work for Jim.

Dieter

--
Though this is a sick signature, it's still a significant signature.



Tue, 08 Apr 2003 03:00:00 GMT  
 putting % in printf
Quote:

> Jean-Philippe Theberge schrieb:

> > Does "printf("The %% of grades is %s",grade)" work?

> It works for me, it works for you and perhaps it even works for Bill.

> But it seems that it doesn't work for Jim.

Actually Jim questioned:
  printf("The \% of grades i %s\n", grade)

not %% which is what the bit about printf in the manual says works

(if you looked :)
Jennifer



Tue, 08 Apr 2003 03:00:00 GMT  
 putting % in printf
Jennifer Cross schrieb:

Quote:


> > Jean-Philippe Theberge schrieb:

> > > Does "printf("The %% of grades is %s",grade)" work?

> > It works for me, it works for you and perhaps it even works for Bill.

> > But it seems that it doesn't work for Jim.
> Actually Jim questioned:
>   printf("The \% of grades i %s\n", grade)

> not %% which is what the bit about printf in the manual says works

> (if you looked :)
> Jennifer


to Bill's
question."
But at that time "Ground Control" had already given the "%%"-answer.

Btw: In my man-page, nothing about printing "%" is mentioned.

Dieter
--
Though this is a sick signature, it's still a significant signature.



Tue, 08 Apr 2003 03:00:00 GMT  
 putting % in printf
Quote:

> Btw: In my man-page, nothing about printing "%" is mentioned.

man awk on my unix box says see also printf
(which says "%%   Print a %; no argument is converted.")

give a man a fish and all that stuff
Jen



Tue, 08 Apr 2003 03:00:00 GMT  
 putting % in printf
Quote:


> to Bill's
> question."
> But at that time "Ground Control" had already given the "%%"-answer.

Oh, I see what you are getting at here...
but guessing at arrival times for news at various places around
the planet has always been tricky, so I never assume someone else
has seen a message unless they have replied into the same stream
as that particular message.

and yes, I'm fully prepared to be right, for small values of right
:)
Jennifer



Tue, 08 Apr 2003 03:00:00 GMT  
 putting % in printf
Jennifer Cross schrieb:

Quote:

> Oh, I see what you are getting at here...
> but guessing at arrival times for news at various places around
> the planet has always been tricky, so I never assume someone else
> has seen a message unless they have replied into the same stream
> as that particular message.

> and yes, I'm fully prepared to be right, for small values of right
> :)

OK - you won ;)

But nevertheless:

printf("The %s of grades is %s", "%", grade)

is tricky. ;)
--
Though this is a sick signature, it's still a significant signature.



Tue, 08 Apr 2003 03:00:00 GMT  
 putting % in printf

Quote:




> > > > Does "printf("The %% of grades is %s",grade)" work?

> > > It works for me, it works for you and perhaps it even works for Bill.

> > > But it seems that it doesn't work for Jim.

> > Actually Jim questioned:

> >   printf("The \% of grades i %s\n", grade)

> > not %% which is what the bit about printf in the manual says works

> > (if you looked :)


> to Bill's question."

I stand by my statement and assert that it is still true: Jennifer's
was the first and only "Right Answer".

Quote:
> But at that time "Ground Control" had already given the "%%"-answer.

Ah, the proverbial "fish" answer! ;-)

Quote:
> Btw: In my man-page, nothing about printing "%" is mentioned.

Which man page? See printf(3).

According to amazon.com, "2 of 2 people found the following review
helpful":

  The book that defines the language., May 10, 1998

  Chapter 2 of The AWK Programming Language serves as the formal
  definition of the language, written by its creators. There is no
  other published standard or official document. So this book is
  the primary, definitive resource for all issues related to the
  awk programming language in general. Other awk resources (e.g.,
  the GNU awk manual) should be regarded as secondary and treated
  as subordinate to The AWK Programming Language. It is especially
  important for contributors to the Usenet newsgroup comp.lang.awk
  to bear this in mind when posting general, version-independent
  information about awk to that newsgroup.

  Owning this book is a prerequisite to becoming an expert awk
  programmer. Though there are other resources available for learning
  awk, both in print and on the Internet, none of them are as succinct
  and as straighforward as The AWK Programming Language.

<http://www.amazon.com/exec/obidos/tg/stores/detail/-/books/020107981X/
customer-reviews/o/002-0547355-9676840>

Please mentally sprinkle the above review with lots of IMHOs and
smilies. :-) I am utterly devoid of passion about my comments.
They're just opinions. I could be wrong.

--
Jim Monty

Tempe, Arizona USA



Tue, 08 Apr 2003 03:00:00 GMT  
 putting % in printf


<snip>

Quote:
>The book that defines the language., May 10, 1998

>Chapter 2 of The AWK Programming Language serves as the formal
>definition of the language, written by its creators. There is no
>other published standard or official document. . . .

I know I'm risking another pissing match, but isn't there a little
something called POSIX? Doesn't POSIX specifiy how (new) awk should
work? Didn't the POSIX spec covering awk appear after TAPL's
publication but before your review above?

TAPL is worth buying, just as K&R is for C. It's the description of the
language by its creators, thus providing a valuable overview of the
language, but it doesn't describe the _current_ language completely.
The latest edition of Robbins's book is more up to date, but it's
longer than TAPL so perhaps less succinct.

Sent via Deja.com http://www.deja.com/
Before you buy.



Tue, 08 Apr 2003 03:00:00 GMT  
 
 [ 16 post ]  Go to page: [1] [2]

 Relevant Pages 

1. SmallEiffel and EiffelBase (COLLECTION.put vs. ARRAY.put)

2. ftp_lib.tcl 2.3 bgerror after timeout of control connection on put and false-positive FTP puts

3. puts -timeout or puts should return n_written

4. printf

5. Problem with printf

6. printf and locale settings

7. printing array elements using printf

8. printf inner part of a string

9. printf ?

10. PRINTF external variable

11. printf

12. printf question

 

 
Powered by phpBB® Forum Software