David Gibbs <dagibbs@qnx.com> wrote:
Augie Henriques <> augiehenriques@hotmail.com> > wrote:
Hi,
I would like to take a user input string into c, perform a conversion
on it and pass it to the format parameter of the printf function.
Is there a function that makes this conversion?
So if the user inputs “%s\n\r” I would like to pass this to the
printf as if it where typed in the code.
This seems ok – why do you need to do a conversion on it?
“\n” isn’t the same as ‘\’ + ‘n’
That’s about the only thing I can think of – Augie will need to do
backslash escape and conversion… Otherwise, “%c\n”, will literally
print the backslash and the n.
Apart from that, like Dave sez, it’s pretty straightforward. I was
waiting for “the catch”…
Cheers,
-RK
Try this little sample program:
#include <stdio.h
void main()
{
char ibuf[80];
char *b;
b = gets(ibuf);
printf(ibuf, b );
printf("\n");
}
If I compile & run it:
Script started on Mon Aug 12 15:16:24 2002
make form
cc form.c -o form
form
%s
%s
form
%x
8047cd0
form
%d
134511824
Script done on Mon Aug 12 15:16:45 2002
Or, maybe I’m missing something you’re trying to do…
-David
QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.
–
Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at www.parse.com.
Email my initials at parse dot com.