anyone can explain me...How printf() function works. there any way to find out the coding of any library function in Turbo C??
To get the code for Turbo C library functions you need to use tlib (included with turboc) - extract the function from the corresponding library (.lib file in directory lib) - disassemble to get an assembly language listing - I do not know if a better tool is available. As to how printf works I am appending the foll program - I am also enclosing as zip file Code: #include <stdio.h> #include <stdarg.h> #include <string.h> /* http://msdn.microsoft.com/en-us/library/kb57fad8%28v=vs.71%29.aspx I used the above link for this example - to get the method of picking trailing args from the stack */ void display_int(int d); void demo_printf(char *narration, ...); /* use ONLY 3 '.' i.e. ... */ void display_str(char *s); void main() { demo_printf("the value of %s is between %d and %d\n***", "PI", 3, 4); } /* our toy implementation of printf */ void demo_printf(char *narration, ...) /* use ONLY 3 '.' i.e. ... to denote variable no of trailing arguments*/ { /* this illustrates use of only %s, %d and \n */ va_list argptr; char *ptr; int d, i; va_start(argptr, narration); for( i = 0; i < strlen(narration); i++ ) { if( narration[ i ] != '%' && narration[ i ] != '\\' ) putc(narration[ i ], stdout); else if( narration[ i ] == '%' ) { if( narration[ i + 1 ] == 'd' ) { d = va_arg(argptr, int); display_int(d); i++; /* skip next char in for loop */ } else if( narration[ i + 1 ] == 's' ) { ptr = va_arg(argptr, char *); display_str(ptr); i++; /* skip next char in for loop */ } } else if( narration[ i + 1 ] == 'n' ) { putc('\n', stdout); i++; } } va_end(argptr); } void display_str(char *s) { int i; for( i = 0; i < strlen(s); i++ ) putc(s[ i ], stdout); } void display_int(int d) { char intstr[ 15 ]; int i; i = sizeof(intstr) - 1; intstr[ i-- ] = 0; /* null terminate*/ for( ; i >= 0 && d; i-- ) { intstr[ i ] = '0' + d % 10; d /= 10; } i++; /* to offset last decrement in for loop */ display_str(intstr + i); }