[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]


    Search the Q&A Archives


...implement printf() function in 'C' ?

<< Back to: comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ)

Question by lak
Submitted on 11/27/2003
Related FAQ: comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ)
Rating: Rate this question: Vote
How to implement printf()  function in 'C' ?


Answer by adnan buland
Submitted on 11/9/2004
Rating: Not yet rated Rate this answer: Vote
printf function show what ever we write.if want to print i love u then apply this
printf("i love u");

 

Answer by Ravi Shankar
Submitted on 12/10/2004
Rating: Not yet rated Rate this answer: Vote
u can create ur own printf function by using BIOS/DOS Interrupts.Turboc c provides some functions like int86(),int86x() to execute interrupts using regs.so u can write a function just like printf() and u can specify parameters 4 that. This is just like mouse events program in c.

 

Answer by Saravanakumar
Submitted on 8/3/2005
Rating: Not yet rated Rate this answer: Vote
#include <stdio.h>
#include <stdarg.h>


int MyPrint(char *fmt, ...)
{
va_list ap;
va_start(ap,fmt);
return(printf(fmt,ap));
}


int main()
{
printf("Hi %s My age is %d years and %f months","Dear",18,3.4);
}

 

Answer by aishwarya
Submitted on 4/14/2006
Rating: Not yet rated Rate this answer: Vote
look for Variable argument lists ...
#include <stdarg.h>

 

Answer by Sumonto
Submitted on 11/15/2006
Rating: Not yet rated Rate this answer: Vote
Include stdarg.h header file and create printf function which can take indefinite number of parameters. ( Refer help on stdarg.h's varlist topic). Make the first parameter of string type. In the function , analyze the string and count no. of % sign which will give you an idea of no. of arguments coming after the string.

 

Answer by ja
Submitted on 1/7/2007
Rating: Not yet rated Rate this answer: Vote
using the library stbarg

 

Answer by kumar
Submitted on 2/22/2007
Rating: Not yet rated Rate this answer: Vote
#define putchar(c)

outbyte(c)
  
static void printchar(char **str, int c)
{
extern int putchar(int c);

if (str)
{
**str = c; ++(*str);
}

else
(void)putchar(c);

}


#define PAD_RIGHT 1
#define PAD_ZERO 2

static int prints(char **out, const char *string, int width, int pad)
         {
    
    register int pc = 0, padchar = ' ';

   if (width > 0)
           {
    register int len = 0;
   
   register const char *ptr;

   for (ptr = string; *ptr; ++ptr)
      ++len;
if (len >= width)
width = 0;
else
width -= len;
if (pad & PAD_ZERO)
padchar = '0';
}
if (!(pad & PAD_RIGHT))
{
for ( ; width > 0; --width)
{ printchar (out, padchar); ++pc; }
}
for ( ; *string ; ++string)
{
printchar (out, *string);
++pc;
}
for ( ; width > 0; --width)
{
printchar (out, padchar);
++pc;
}
return pc;
}

 

Your answer will be published for anyone to see and rate.  Your answer will not be displayed immediately.  If you'd like to get expert points and benefit from positive ratings, please create a new account or login into an existing account below.


Your name or nickname:
If you'd like to create a new account or access your existing account, put in your password here:
Your answer:

FAQS.ORG reserves the right to edit your answer as to improve its clarity.  By submitting your answer you authorize FAQS.ORG to publish your answer on the WWW without any restrictions. You agree to hold harmless and indemnify FAQS.ORG against any claims, costs, or damages resulting from publishing your answer.

 

FAQS.ORG makes no guarantees as to the accuracy of the posts. Each post is the personal opinion of the poster. These posts are not intended to substitute for medical, tax, legal, investment, accounting, or other professional advice. FAQS.ORG does not endorse any opinion or any product or service mentioned mentioned in these posts.

 

<< Back to: comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ)


[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]

© 2008 FAQS.ORG. All rights reserved.