All of lore.kernel.org
 help / color / mirror / Atom feed
* Printf and scanf
@ 2005-06-05 12:21 Ankit Jain
  2005-06-05 13:54 ` Arturas Moskvinas
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Ankit Jain @ 2005-06-05 12:21 UTC (permalink / raw)
  To: linux prg, newbie

hi

this is a simple problem which somebody asked me and i
am not able to solve. if somebody here can help me out

i just want to know how scanf function can be used on
the place of printf and vice versa

thanks

ankit

Send instant messages to your online friends http://uk.messenger.yahoo.com 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Printf and scanf
  2005-06-05 12:21 Printf and scanf Ankit Jain
@ 2005-06-05 13:54 ` Arturas Moskvinas
  2005-06-05 14:03   ` Eric Bambach
  2005-06-05 13:59 ` Steve Graegert
  2005-06-24 21:20 ` Hendrik Visage
  2 siblings, 1 reply; 7+ messages in thread
From: Arturas Moskvinas @ 2005-06-05 13:54 UTC (permalink / raw)
  To: Ankit Jain; +Cc: linux prg, newbie

> hi
> 
> this is a simple problem which somebody asked me and i
> am not able to solve. if somebody here can help me out
> 
> i just want to know how scanf function can be used on
> the place of printf and vice versa

Scanf reads from STDIN and printf writes into STDOUT. I do not think
there is any way to change reading operation with writing... Of course
some alchemy might help you :)

I think you misinterpreted something...

Arturas Moskvinas

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Printf and scanf
  2005-06-05 12:21 Printf and scanf Ankit Jain
  2005-06-05 13:54 ` Arturas Moskvinas
@ 2005-06-05 13:59 ` Steve Graegert
  2005-06-24 21:20 ` Hendrik Visage
  2 siblings, 0 replies; 7+ messages in thread
From: Steve Graegert @ 2005-06-05 13:59 UTC (permalink / raw)
  To: Ankit Jain; +Cc: linux-newbie

On 6/5/05, Ankit Jain <ankitjain1580@yahoo.com> wrote:
> hi

Hello,

> i just want to know how scanf function can be used on
> the place of printf and vice versa

Hmm, I think I do not understand your question.  Can you give an
example of what you want to achive?

Kind Regards

    \Steve

--

Steve Graegert <graegerts@gmail.com>
Independent Software Consultant {C/C++ && Java && .NET}
Mobile: +49 (176)  21 24 88 69
Office: +49 (9131) 71 26 40 9
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Printf and scanf
  2005-06-05 13:54 ` Arturas Moskvinas
@ 2005-06-05 14:03   ` Eric Bambach
  0 siblings, 0 replies; 7+ messages in thread
From: Eric Bambach @ 2005-06-05 14:03 UTC (permalink / raw)
  To: Arturas Moskvinas; +Cc: linux prg

On Sunday 05 June 2005 08:54 am, Arturas Moskvinas wrote:
> > hi
> >
> > this is a simple problem which somebody asked me and i
> > am not able to solve. if somebody here can help me out
> >
> > i just want to know how scanf function can be used on
> > the place of printf and vice versa
>
> Scanf reads from STDIN and printf writes into STDOUT. I do not think
> there is any way to change reading operation with writing... Of course
> some alchemy might help you :)
>
> I think you misinterpreted something...

I agree. At a most basic level printf copies its arguments into STDOUTs 
buffer. Scanf reads from STDINs buffer and copies to its arguments memory 
space. There is no way to make these functions behave differently. Perhaps 
with fprintf and fscanf you can make some magic...but its a silly exercise 
and would make code unholy and unreadable.
> Arturas Moskvinas
> -
> To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.linux-learn.org/faqs

-- 
----------------------------------------
--EB

> All is fine except that I can reliably "oops" it simply by trying to read
> from /proc/apm (e.g. cat /proc/apm).
> oops output and ksymoops-2.3.4 output is attached.
> Is there anything else I can contribute?

The latitude and longtitude of the bios writers current position, and
a ballistic missile.

                --Alan Cox LKML-December 08,2000 

----------------------------------------
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Printf and scanf
  2005-06-05 12:21 Printf and scanf Ankit Jain
  2005-06-05 13:54 ` Arturas Moskvinas
  2005-06-05 13:59 ` Steve Graegert
@ 2005-06-24 21:20 ` Hendrik Visage
  2005-06-27 18:11   ` Andriot
  2 siblings, 1 reply; 7+ messages in thread
From: Hendrik Visage @ 2005-06-24 21:20 UTC (permalink / raw)
  To: Ankit Jain; +Cc: linux prg, newbie

On 6/5/05, Ankit Jain <ankitjain1580@yahoo.com> wrote:

> i just want to know how scanf function can be used on
> the place of printf and vice versa

In the Obfuscated C contest one of the first/early entries is one that
states "Using read to write" (Or something to similar extend, or
perhaps even using scanf to print). Reading that code is hackery, and
from my first glance at the code, it was don't with quote and macro
hackery.

Thus you could #define scanf __prinf and #define printf __scanf... or
something with similar confusing

-- 
Hendrik Visage
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Printf and scanf
  2005-06-24 21:20 ` Hendrik Visage
@ 2005-06-27 18:11   ` Andriot
  2005-06-28  3:42     ` joy merwin monteiro
  0 siblings, 1 reply; 7+ messages in thread
From: Andriot @ 2005-06-27 18:11 UTC (permalink / raw)
  To: Hendrik Visage; +Cc: Ankit Jain, linux prg, newbie

Hendrik Visage wrote:

>On 6/5/05, Ankit Jain <ankitjain1580@yahoo.com> wrote:
>
>  
>
>>i just want to know how scanf function can be used on
>>the place of printf and vice versa
>>    
>>
>
>In the Obfuscated C contest one of the first/early entries is one that
>states "Using read to write" (Or something to similar extend, or
>perhaps even using scanf to print). Reading that code is hackery, and
>from my first glance at the code, it was don't with quote and macro
>hackery.
>
>Thus you could #define scanf __prinf and #define printf __scanf... or
>something with similar confusing
>  
>

Of course, it is not possible to use directly printf like a scanf ;)
But you can use printf to write some values into arguments when you call 
the function. This uses special caracters you put in the format string. 
And this should prevent you to call printf with a string the user wrote, 
because this is a very big security hole.

JP



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Printf and scanf
  2005-06-27 18:11   ` Andriot
@ 2005-06-28  3:42     ` joy merwin monteiro
  0 siblings, 0 replies; 7+ messages in thread
From: joy merwin monteiro @ 2005-06-28  3:42 UTC (permalink / raw)
  To: Andriot; +Cc: linux-newbie

Now you have piqued my interest.......
what special characters??
any place on the net I can read up on this?

Joy


On 6/27/05, Andriot <andriot@6wind.com> wrote:
> Hendrik Visage wrote:
> 
> >On 6/5/05, Ankit Jain <ankitjain1580@yahoo.com> wrote:
> >
> >
> >
> >>i just want to know how scanf function can be used on
> >>the place of printf and vice versa
> >>
> >>
> >
> >In the Obfuscated C contest one of the first/early entries is one that
> >states "Using read to write" (Or something to similar extend, or
> >perhaps even using scanf to print). Reading that code is hackery, and
> >from my first glance at the code, it was don't with quote and macro
> >hackery.
> >
> >Thus you could #define scanf __prinf and #define printf __scanf... or
> >something with similar confusing
> >
> >
> 
> Of course, it is not possible to use directly printf like a scanf ;)
> But you can use printf to write some values into arguments when you call
> the function. This uses special caracters you put in the format string.
> And this should prevent you to call printf with a string the user wrote,
> because this is a very big security hole.
> 
> JP
> 
> 
> -
> To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.linux-learn.org/faqs
> 


-- 
<ed__> riel: if it were a vax, gcc would probably be an opcode

	- excerpt from #kernelnewbies
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2005-06-28  3:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-05 12:21 Printf and scanf Ankit Jain
2005-06-05 13:54 ` Arturas Moskvinas
2005-06-05 14:03   ` Eric Bambach
2005-06-05 13:59 ` Steve Graegert
2005-06-24 21:20 ` Hendrik Visage
2005-06-27 18:11   ` Andriot
2005-06-28  3:42     ` joy merwin monteiro

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.