can any one tell how to write coding for a printf statement
without using printf command?
can any one tell how to write coding for a printf statement
without using printf command?
You mean you want to write your own version of printf()?
Well printf() wraps the functionality of the operating system that you have. So for Unix, printf() probably ends up calling write() or another function that ends up calling write(). For Windows, it's either WriteConsole() or WriteFile() (I think WriteConsole() calls WriteFile(), but I can't back that up at the moment).
All in all, it depends upon the O/S you're using.
can you be a littlie bit more specific
couldnt understand what u told
A Variable argument list perhaps?
shuaib.akram: I think YOU need to be more specific about what you actually need to do. If you want to implement your own version of printf, that's possible to do - to make a reasonable attempt will be some 50-100 lines of fairly complex C-code [this is not a full implementation, that's more like 200-500 lines of even more complex code].
But either one is certainly not a beginners task. The first step is to handle variable arguments to a function, which means include <stdarg.h> to your function - play with that and make that work for something simple that uses for example printf to print the 2 or more variables you've supplied to the function, making the first argument being the number of arguments.
Once you have the idea of that, post back.
If this isn't actually what you are intending to do, then please rephrase your question to explain better what you want to do.
--
Mats
sorry for the unclear question
we can write code for all the inbuilt functions with out using that inbuilt function
for example
strlen(stringname) gives length of the string
but without using that function we can write the code to find length
here i gives the length of stringCode:for(i=0;i<10;i++);
i wanted to know if we can write the same type of code for printf
hope this is clear!!
Yes you can.
Some text books show a primitive example.
Some manual pages for stdarg.h / va_start() also show examples.
Most of the standard C library is written in C itself, so all you really need to do is find the source code for glibc and you're done.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.