top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

C: How I can write my own printf() function ?

+3 votes
790 views
C: How I can write my own printf() function ?
posted Nov 29, 2016 by Ganesh Kumar

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

You can use variable argument list.
Try to check for va_list, va_start(), va_end()

Here is a sample program

#include <stdio.h>
#include <stdarg.h>

int my_printf(char* format, ...)
{
    va_list arg;
    int ret =0;

    va_start(arg, format);

    ret = vfprintf(stderr, format, arg);
    va_end(arg);

    return ret; 
}

int main()
{
    my_printf("Welcome to QueryHome\n");

    return 0;
}
answer Nov 30, 2016 by Arshad Khan
Similar Questions
+1 vote

Write your own rand function which returns random numbers in a given range(input) so that the numbers in the given range is equally likely to appear.

+1 vote

I want to build my own library in C, can someone help me with this?

+5 votes

I don't want to use any library functions, Interested in How to write your own Pow(X(double),Y(double)) functions in most optimized way... can somebody help me out?

...