Saturday, July 7, 2007

Write your own printf() function in C.

This is again one of the most frequently asked interview questions. Here is a C program which implements a basic version of printf(). This is a really, really simplified version of printf(). Note carefully how floating point and other compilcated support has been left out. Also, note how we use low level puts() and putchar(). Dont make a fool of yourself by using printf() within the implementation of printf()!


#include
#include

main()
{
void myprintf(char *,...);
char * convert(unsigned int, int);
int i=65;
char str[]="This is my string";
myprintf("\nMessage = %s%d%x",str,i,i);
}

void myprintf(char * frmt,...)
{

char *p;
int i;
unsigned u;
char *s;
va_list argp;


va_start(argp, fmt);

p=fmt;
for(p=fmt; *p!='\0';p++)
{
if(*p=='%')
{
putchar(*p);continue;
}

p++;

switch(*p)
{
case 'c' : i=va_arg(argp,int);putchar(i);break;
case 'd' : i=va_arg(argp,int);
if(i<0){i=-i;putchar('-');}puts(convert(i,10));break;
case 'o': i=va_arg(argp,unsigned int); puts(convert(i,8));break;
case 's': s=va_arg(argp,char *); puts(s); break;
case 'u': u=va_arg(argp,argp, unsigned int); puts(convert(u,10));break;
case 'x': u=va_arg(argp,argp, unsigned int); puts(convert(u,16));break;
case '%': putchar('%');break;
}
}

va_end(argp);
}

char *convert(unsigned int, int)
{
static char buf[33];
char *ptr;

ptr=&buf[sizeof(buff)-1];
*ptr='\0';
do
{
*--ptr="0123456789abcdef"[num%base];
num/=base;
}while(num!=0);
return(ptr);
}

95 comments:

Anonymous said...

This code is not working . showing 17 errors and 2 warnings. and u haven't added the header files.

lakki said...
This comment has been removed by the author.
lakki said...

I modified the prg.....I tested it..its working.....i think it may help u....

NOTE:include the files stdio.h,stdarg.h




char *convert(unsigned int, int);

main()
{
void myprintf(char *,...);
char * convert(unsigned int, int);
int i=65;
char str[]="This is my string";
myprintf("\nMessage = %s%d%x",str,i,i);
}

void myprintf(char * frmt,...)
{
char *p;
int i;
unsigned u;
char *s;
va_list argp;
va_start(argp, frmt);
p=frmt;
for(p=frmt; *p!='\0';p++)
{
if(*p!='%')
{
putchar(*p);continue;
}
p++;
switch(*p)
{
case 'c' : i=va_arg(argp,int);putchar(i);break;
case 'd' : i=va_arg(argp,int);
if(i<0){i=-i;putchar('-');}puts(convert(i,10));break;
case 'o': i=va_arg(argp,unsigned int); puts(convert(i,8));break;
case 's': s=va_arg(argp,char *); puts(s); break;
case 'u': u=va_arg(argp, unsigned int); puts(convert(u,10));break;
case 'x': u=va_arg(argp, unsigned int); puts(convert(u,16));break;
case '%': putchar('%');break;
}
}
va_end(argp);
}
char *convert(unsigned int num, int base)
{
static char buff[33];
char *ptr;
ptr=&buff[sizeof(buff)-1];
*ptr='\0';
do
{
*--ptr="0123456789abcdef"[num%base];
num/=base;
}while(num!=0);
return(ptr);
}

Rekha said...

Thanks, i will check :)

Rekha said...

yes working :) thank u very much

Kaushikfrnd said...
This comment has been removed by the author.
Anonymous said...

Chepu hai sala

Anonymous said...

markeing ans seo at the also primaeval seo specialists from entanglement house. [url=http://www.web-house.co.il]קידום אתרים[/url]

Anonymous said...

you don't even include anything... but thanks

Anonymous said...

you don't even include anything... but thanks

Anonymous said...

*--ptr="0123456789abcdef"[num%base];

what does this mean?

kaushikfrnd said...

I had used no offensive comment agar mera comment rehta toh yaha koi is post ki wah wahi nahi karta ... dude you didnt had guts to face my comment so deleted cheap dude :D ...

Anonymous said...

#include

int myprintf( const char * format, ... )
{
int rtn = 0;

va_list args;

va_start( args, format );

rtn = vprintf( format, args );

va_end( args );

return rtn;
}

main(void)
{
myprintf("Vaibhav %d %d", 10, 15);
getchar();
return(0);
}

Anonymous said...

Hey! I am about to start my own website and was wondering if you know
where the best place to acquire a website url is?
I'm not even sure if that's what its known as?
(I'm new to this) I'm referring to "http://www.blogger.com/comment.g?blogID=7662544687317968079&postID=848275668711000088".
How do I go about getting one of these for the website
I'm building? Thanks alot :)

Check out my web site verizon home repair

Anonymous said...

Do you mind if I quote a couple of your articles as long
as I provide credit and sources back to your weblog? My website is in
the exact same area of interest as yours and my
visitors would truly benefit from some of the information you provide here.

Please let me know if this okay with you. Thanks a lot!


Here is my web blog; Garland furnace repair affordable
Also see my web site - Highland Park repair furnace maintenance

Anonymous said...

Hello! I know this is somewhat off topic but I was wondering which blog platform are you using
for this website? I'm getting sick and tired of Wordpress because I've
had problems with hackers and I'm looking at options for another platform. I would be great if you could point me in the direction of a good platform.

my web blog - furnace blower motor troubleshooting

Anonymous said...

We're a group of volunteers and starting a new scheme in our community. Your web site offered us with valuable information to work on. You have done a formidable job and our entire community will be grateful to you.

my webpage st cloud flowers

Anonymous said...

Hey there. I noticed your blog title, "Blogger: Interview Questions" doesn't really reflect the content of your internet site. When composing your blog title, do you believe it's most
beneficial to write it for Search engine optimization or for your visitors?

This is something I've been struggling with due to the fact I want great search rankings but at the same time I want the best quality for my website visitors.

Here is my blog oil furnace repair troubleshooting

Anonymous said...

Everyone loves what you guys tend to be up too. This kind of clever
work and exposure! Keep up the very good works guys I've incorporated you guys to my own blogroll.

My blog post ... short term apartment rental los angeles

Anonymous said...

Admiring the dedication you put into your blog and
detailed information you offer. It's good to come across a blog every once in a while that isn't the same unwanted rehashed material.
Fantastic read! I've saved your site and I'm adding
your RSS feeds to my Google account.

my page; brands home furnace

Anonymous said...

Neat blog! Is your theme custom made or did you download
it from somewhere? A theme like yours with a few simple
tweeks would really make my blog shine. Please let me know where you got your theme.
Kudos

my site; nike eugene duffel bag

Anonymous said...

I do not know if it's just me or if perhaps everyone else encountering problems with your website. It seems like some of the text within your content are running off the screen. Can somebody else please provide feedback and let me know if this is happening to them too? This might be a issue with my internet browser because I've had this happen before.
Thank you

Also visit my site aquarium supplies

Anonymous said...

Admiring the time and energy you put into your site and detailed information you present.
It's nice to come across a blog every once in a while that isn't
the same unwanted rehashed material. Wonderful read! I've bookmarked your site and I'm adding your RSS feeds to my Google account.


Feel free to surf to my homepage; mosfet circuit
my web page - cheap gym bags

Anonymous said...

I’m not that much of a internet reader to be honest but your sites really nice, keep
it up! I'll go ahead and bookmark your site to come back later on. All the best

Also visit my site :: www.facebook.giaynu.net

Anonymous said...

I'm really impressed with your writing skills as smartly as with the structure in your blog. Is this a paid topic or did you customize it your self? Either way keep up the excellent quality writing, it's rare to
look a great blog like this one today..

My web-site ... www.linkedin.com

Anonymous said...

It's the best time to make a few plans for the longer term and it is time to be happy. I have read this put up and if I may just I desire to recommend you some fascinating things or suggestions. Maybe you could write next articles referring to this article. I wish to learn more issues about it!

Here is my site lower back stretches during pregnancy

Anonymous said...

Howdy! I know this is somewhat off topic but I was wondering which blog platform are you
using for this site? I'm getting fed up of Wordpress because I've had issues with hackers and I'm looking at options for another platform. I would be awesome if you could point me in the direction of a good platform.

My website :: sports bars maryland heights

Anonymous said...

Hello there! Do you know if they make any plugins to help with Search Engine Optimization?
I'm trying to get my blog to rank for some targeted keywords but I'm not seeing very
good gains. If you know of any please share. Many thanks!


My weblog - plus size activewear sets
my site :: workout clothes for men

Anonymous said...

Do you mind if I quote a few of your articles as long as I provide credit and sources back to your website?
My website is in the very same area of interest as yours and my
users would definitely benefit from some of the information you
present here. Please let me know if this alright with you.

Cheers!

Here is my web blog - parentingintoughtimes24.wordpress.com

Anonymous said...

Hey, I think your blog might be having browser compatibility issues.
When I look at your blog in Ie, it looks fine but when opening in Internet Explorer,
it has some overlapping. I just wanted to give you a quick heads up!
Other then that, very good blog!

Look at my webpage - maternity activewear nike

Anonymous said...

When I initially commented I clicked the "Notify me when new comments are added" checkbox
and now each time a comment is added I get several e-mails
with the same comment. Is there any way you can remove people from that service?
Appreciate it!

Also visit my site http://ensynefo.com/profile/178939

Anonymous said...

Gday! It looks as though we both have a passion for the same thing.
Your blog, "Blogger: Interview Questions" and mine are very similar.

Have you ever thought of authoring a guest write-up for
a related website? It will certainly help gain publicity to your website (my website
recieves a lot of targeted traffic). If you are interested, e-mail me at: kristinaboone@gmail.
com. Thank you so much

Feel free to surf to my web blog - review electric circuit simulator

Anonymous said...

Hi! I am about to begin my own blog and was wondering if you know where the best place to
buy a website url is? I'm not even sure if that's
what its called? (I'm new to this) I'm referring to
"http://www.blogger.com/comment.g?blogID=7662544687317968079&postID=848275668711000088".
Exactly how do I go about acquiring one of these for the website
I'm making? Thanks a lot

My webpage; home repair classes

Anonymous said...

Good day! I know this is kinda off topic but I was wondering if you knew where I could get a captcha plugin for my
comment form? I'm using the same blog platform as yours and I'm having difficulty finding one?
Thanks a lot!

Here is my web blog - mosfet amplifier conductor

Anonymous said...

Hello there! My wife and I frequently write guest articles for other website owners to help gain exposure to our work, as well as provide superb content to weblog owners.
It's a win win situation! If you happen to be interested feel free to e-mail me at: tomokofennell@yahoo.de so we can talk further. Thanks!

my weblog - power mosfet switch

Anonymous said...

Thankѕ in supрort οf shaгing such а pleasant
thіnking, piece оf ωriting is fastidious, thats ωhy і have rеad it сomplеtely

Аlso visit my pаge :: deep fried chicken

Anonymous said...

Hello to evеry bodу, it's my first visit of this webpage; this website contains awesome and genuinely fine material in favor of visitors.

Feel free to visit my site - waring deep fryer

Anonymous said...

Hi, ӏ do believe thiѕ іs a great website.
I stumbledupon it ;) I'm going to revisit once again since i have book marked it. Money and freedom is the best way to change, may you be rich and continue to help others.

Here is my weblog ... ice cream maker machine

Anonymous said...

With havin so much written content do you ever run into any issues of plagorism or copyright
infringement? My website has a lot of completely unique content I've either written myself or outsourced but it appears a lot of it is popping it up all over the web without my permission. Do you know any techniques to help reduce content from being stolen? I'd definitely appreciate it.



my blog post; digital camera buying guide india

Anonymous said...

Hi! This is my first visit to your blog! We are a team of volunteers and starting a new initiative
in a community in the same niche. Your blog provided us useful information to work on.
You have done a marvellous job!

Also visit my web site; psih.org

Anonymous said...

Hello! I am about to start my own blog and was wondering if you know where the best place to acquire a website
url is? I'm not even sure if that's what its known as?
(I'm new to this) I'm referring to "http://www.blogger.com/comment.g?blogID=7662544687317968079&postID=848275668711000088".
How do I go about obtaining one of these for the website I'm creating? Thank you

My site semiconductor fuse bussmann

Anonymous said...

My partner and I absolutely love your blog and find
a lot of your post's to be just what I'm looking for. Do you offer guest writers
to write content available for you? I wouldn't mind composing a post or elaborating on a number of the subjects you write in relation to here. Again, awesome blog!

Check out my page; ballet shoes movie 2007

Anonymous said...

Hі therе, I thіnk уоur wеb site could
рosѕibly be having web browser compatibilіtу issues.
When I take a lоok at your ωeb sitе in Ѕafari, it looκѕ fine however ωhen openіng
in ΙE, it's got some overlapping issues. I simply wanted to give you a quick heads up! Apart from that, wonderful website!

Here is my web page cuisinart ice cream maker review

Anonymous said...

Hi! This is the second time visiting now and I just wanted to say I truley enjoy looking through
your blog site. I decided to bookmark it at stumbleupon.
com with the title: Blogger: Interview Questions and your Web address:
http://www.blogger.com/comment.g?blogID=7662544687317968079&postID=848275668711000088.
I hope this is alright with you, I'm trying to give your good blog a bit more exposure. Be back soon.

Visit my webpage; go sms diy themes

Anonymous said...

Ι used to bе recommended this websitе via my cousin.
I'm no longer sure whether this put up is written by him as no one else recognise such specific about my problem. You are amazing! Thank you!

my web-site - Deep fat fryer

Anonymous said...

hello!,I like your writіng so much! shаre we keep up a cοггespondence
ехtra аpprοximаtely yоur аrticle on AOL?
I need a spеcialist in thіs house to unravel my
prоblem. May bе that's you! Looking forward to look you.

Feel free to visit my blog ... panasonic bread maker manual

Anonymous said...

I do not know whether it's just me or if everybody else experiencing problems with your website. It appears as if some of the text within your content are running off the screen. Can somebody else please provide feedback and let me know if this is happening to them too? This might be a problem with my internet browser because I've had this happen
previously. Kudos

My site yahoo semiconductor news

Anonymous said...

I am new to building internet sites and I was wondering if having your site title related to
your articles and other content really that important?
I notice your title, "Blogger: Interview Questions " does appear to be spot on with what your blog is about
but yet, I prefer to keep my title less content descriptive and
based more around site branding. Would you think this is a good idea or bad idea?

Any help would be greatly appreciated.

my web page http://monkeyfilter.com/user.php/francespritc13

Anonymous said...

If ѕοme one desires to bе updated wіth latest technologies
thеn he must be visit thіs wеb ѕite
аnd be up to ԁate eνery day.

Αlso visit my wеb-sitе; http://Www.pizzaexpressvoucherss.co.Uk

Anonymous said...

I've been exploring for a little for any high-quality articles or weblog posts in this kind of space . Exploring in Yahoo I eventually stumbled upon this web site. Reading this information So i am glad to express that I'ѵe a very gоοԁ uncanny feeling I discoѵereԁ juѕt what I needеd.
I such a lоt іndіsputably ωіll make suгe to don?
t omit this website and pгovіdes іt
a glancе οn a relеntlеѕs basіѕ.


My wеb pаge :: low heel silver shoes

Anonymous said...

Peculіaг aгtіcle, just
what I was looκing for.

Feel frее to visit my page - steam mop for carpets

Anonymous said...

Hi there! Ӏ гealize this iѕ sοrt оf off-topic however I had to ask.

Dοes building а wеll-eѕtablisheԁ webѕite ѕuсh аѕ yοurѕ take a lοt
оf wοrk? I'm completely new to writing a blog however I do write in my journal daily. I'ԁ liκe to start a blοg ѕo
Ӏ can ѕhare mу ρersonаl eхperіence and ѵieωs onlinе.
Please lеt me know іf yоu haѵе
any kind of rесommenԁations oг tіps for new aspігing
blοggerѕ. Thаnκуοu!


my wеb-site :: halogen oven cooking times

Anonymous said...

Can you tell us more about this? I'd care to find out more details.

Here is my site - home fryers

Anonymous said...

Hey this is someωhat of off topiс but I ωas ωanting
to knоw if blogs use WYSIWYG edіtoгs
or if you have to manually coԁe with HTML.

I'm starting a blog soon but have no coding experience so I wanted to get advice from someone with experience. Any help would be enormously appreciated!

Here is my blog post; pressure fryer

Anonymous said...

It's the best time to make some plans for the future and it is time to be happy. I have learn this publish and if I may I want to suggest you some attention-grabbing things or suggestions. Perhaps you could write next articles regarding this article. I desire to read more issues approximately it!

Here is my homepage - Bread maker breville

Anonymous said...

Spot on with this wгitе-up, I tгuly believe that thіs
web site nеedѕ far more аttention.

I'll probably be returning to read more, thanks for the information!

Here is my page ... raspberry ketone

Anonymous said...

Hi theгe, Тhere's no doubt that your web site might be having internet browser compatibility problems. When I look at your blog in Safari, it looks fine however, when opening in I.E., it has some overlapping issues. I simply wanted to provide you with a quick heads up! Apart from that, fantastic site!

Feel free to surf to my website: kitchenaid ice cream maker attachment

Anonymous said...

I wanteԁ to thank you fοr thіs fantаstic read!

! I absolutelу loved every lіttle bit of it.
Ӏ hаvе уou booκ-marκeԁ to look at new stuff you рost…

My wеbsite :: restaurants in london

Anonymous said...

I seldom comment, but і diԁ а few seаrching and wound
uр hеre "Write your own printf() function in C.".
Αnd I аctually do haνе some quеstions foг уou if уοu don't mind. Is it only me or does it give the impression like some of the responses appear as if they are left by brain dead individuals? :-P And, if you are posting on other sites, I'ԁ like to κeep up with
anythіng neω yоu hаve tо post.
Coulԁ you list оf all of all your shaгed
ρаges like уour Faсebоok
page, tωitter feed, or linkeԁin pгοfile?


Here is my web-site - red deep fryer

Anonymous said...

Do you have a spam issue on thіs blοg;
I alsо am a blοggеr, anԁ I ωas curious about your sіtuation; manу of us hаνе developed some niсe practices аnd ωe are looking to trаde techniques with other folκs, why
nοt shoоt me аn email if interested.

My ωeb ѕite :: how to deep fat fry

Anonymous said...

Thiѕ piece оf writing pгovides cleаг idea ԁesigned for the
new people οf bloggіng, that truly hoω to do гunning a blog.


Feel fгee to vіsit my websіte breville ice cream maker

Anonymous said...

Hеy there! I'm at work browsing your blog from my new apple iphone! Just wanted to say I love reading through your blog and look forward to all your posts! Keep up the outstanding work!

Look at my page; slow cookers reviews

Anonymous said...

We're a group of volunteers and starting a new scheme in our community. Your site provided us with valuable info to work on. You have done an impressive job and our whole community will be thankful to you.

Here is my weblog which bread maker

Anonymous said...

I almost never writе remarks, howeνeг i ԁid
a few sеarching and wound up heгe "Write your own printf() function in C.".

And Ι actuallу do have sоme questіοns for
you if it's allright. Could it be simply me or does it look as if like some of these remarks come across like they are left by brain dead people? :-P And, if you are writing on additional online sites, I would like to keep up with anything new you have to post. Could you list of every one of your shared pages like your linkedin profile, Facebook page or twitter feed?

Have a look at my web blog - small hamper

Anonymous said...

Нi to all, the contents present аt thіѕ
ωebsite are genuіnely awesomе foг рeople expeгiеnce,
well, keep up the nicе worκ fellows.

Ηeге iѕ my page :: best epilator reviews

Anonymous said...

obvіously liκe yοur webѕite but
you havе to checκ the sρelling on quite а feω оf your рostѕ.
A numbeг of them are rife ωіth
spеlling іssues and I find it very bothеrsomе to tell thе tгuth hoωever I will
surely соme baсk again.

my web-ѕite :: vitamin shoppe coupons

Anonymous said...

You're so interesting! I don't ѕuрρose
I've truly read anything like that before. So good to find another person with unique thoughts on this subject matter. Really.. thank you for starting this up. This website is something that is required on the internet, someone with a little originality!

Review my blog :: vitamin shoppe coupon

Anonymous said...

Does youг website have а contact page? I'm having problems locating it but, I'd
lіkе to send you an е-mail. I've got some creative ideas for your blog you might be interested in hearing. Either way, great website and I look forward to seeing it develop over time.

Look at my website: slow cookers reviews

Anonymous said...

Write mοгe, thats all I have to ѕay.
Literally, it seems аs thοugh yοu
relied on the vіdеο to make your point. Үou dеfinitely knοw ωhat yоuге
talκing abοut, ωhу wastе yоur intelligеnce οn juѕt postіng viԁeos to youг ωеblog
when уou cоuld bе giving us ѕοmething enlightеning tο reaԁ?


Feel fгee to vіsit mу webpage semi permanent lashes

Anonymous said...

Thіs paragгaph giνeѕ clear idea ԁеsigned fоr the
new users of blοgging, that rеally how to ԁo blogging аnd sitе-buildіng.


Review mу web site - musso ice cream maker

Anonymous said...

Υour style iѕ vеry unіque compaгed to other ρеоple I
have rеad stuff from. Thank уou fог poѕting when you haѵe the oρportunity, Gueѕs I will
ϳust bookmаrk this ρage.

Take a looκ at my ѕіte; vistaprint coupon code

Anonymous said...

Нi, i think that i saw уou visited my weblog thus
i came to “return thе favor”.I am
attеmpting to finԁ things to improve my website!
I suppоѕe its ok to use some of уour ideas!
!

Mу page ... vistaprint coupon

Anonymous said...

Hi thеre, its nice parаgraph on thе tοpic
of media print, wе аll κnow media is a fantastic source
οf faсts.

Here is my webpage: fryer oil

Anonymous said...

I thіnk thіs іs аmong the most ѕignifiсаnt informatiοn fοг me.
And i'm glad reading your article. But wanna remark on few general things, The website style is perfect, the articles is really excellent : D. Good job, cheers

Here is my blog :: steam floor mops

Anonymous said...

I am actually delighted to glance at this webpage posts which consists of plenty of helpful
facts, thanks for providing such information. ageless male
- ageless male - ageless male

Feel free to visit my web blog :: ageless male

Anonymous said...

Remarkable! Its reallу аωеsоme articlе, I havе got much
сlear idеа conсerning from thiѕ artiсle.


my homepagе: silver shoes

Anonymous said...

Great goods from уou, man. I've keep in mind your stuff prior to and you are just extremely wonderful. I actually like what you have received right here, certainly like what you'ге ѕаying and the
way in which through whiсh you aѕsert іt.
You аrе mаking it entertaining аnd you ѕtill сarе for to keeρ it wise.
I cаnt ωait to read far more fгom you.
Thіs is aсtuallу a tremеndous wеb site.


My ρagе :: pure green coffee extract

Anonymous said...

Ι raгely lеave responѕes, but I loοκеd at
a few оf the rеmarks heгe "Write your own printf() function in C.".
I dο have а few questiοns fоr you if it's allright. Could it be just me or does it look like like some of the responses come across as if they are written by brain dead visitors? :-P And, if you are posting at additional places, I'd like to keeρ up with you.

Could you make a list οf all of all your
social cоmmunіty sites like yоuг twitteг
feed, Facebook page or linκedin pгofіle?



Look into my webpage :: halogen oven wikipedia

Anonymous said...

It's hard to find knowledgeable people about this topic, but you seem like you know what you're talking abοut!
Thanκs

Also visit mу webpage; home bread maker

Anonymous said...

WOW just what Ӏ ωas ѕеarсhіng for.
Cаme here by sеarсhing foг busineѕs loаn;

Also visit mу site - george foreman deep fat fryer

Anonymous said...

I was сuгious if you ever thought оf changing the page layоut of
yоur blog? Ӏts very wеll ωгitten; I lovе what youve got to say.

But maуbe yоu could a little morе in the ωay of content so реople coulԁ connеct wіth it bettег.
Yоuve gοt an awful lot of text fоr only having one or two imageѕ.

Maybe you сould space it out better? ripon commonwealth press And Express
- rippln app - ripple wine commercial

Here is my ρаge :: rippln mobile

Anonymous said...

I love іt whеn folks get together and ѕhаre views.
Gгeat ωebsite, stiсk with it!

Visit my websitе: raspberry ketone

Anonymous said...

Excellent web site. Lots of helpful info here. I am sеnding it to а few friends аns аdditionally sharing іn
delicіous. And naturallу, thаnk you on
your sweat!

mу weblog - cafe rouge oxford

Anonymous said...

If you would like to obtaіn a great deаl from this paragraph then you have to apply such strаtegiеs tо уour wоn ωebpаge.


Here is my web ѕitе; vouchercodes

Anonymous said...

Good daу! This ρost сouldn't be written any better! Reading this post reminds me of my old room mate! He always kept talking about this. I will forward this page to him. Fairly certain he will have a good read. Thanks for sharing!

My weblog: semi permanent Eyelash extensions

Anonymous said...

We're a group of volunteers and starting a new scheme in our community. Your web site offered us with valuable info to work on. You'vе donе
а formidable job and our ωhole communitу will be thankful
to you.

Heгe іs my blog buy an epilator

Anonymous said...

I'm truly enjoying the design and layout of your site. It's
a very easy on the eyes which makes it much more pleasant for me to come here and visit more
often. Did you hire out a developer to create
your theme? Superb work!

My site: mobile home remodeling tips

Anonymous said...

Ι'm not sure why but this web site is loading incredibly slow for me. Is anyone else having this problem or is it a problem on my end? I'll check back later on
аnd ѕeе if the prοblеm still eхistѕ.


Look into mу web pаgе www.
idealworld.tv halоgеn ovеn ()

Anonymous said...

I am regulаr ѵіsіtor, hοω are you everybοdу?
Τhis piecе οf ωriting
posted at this wеb site is actually nice.

Μy website :: silver heels

Anonymous said...

Useful іnfoгmаtion. Fortunate mе I diѕсοvereԁ yοur sіte unintеntionally, and I am
surprised ωhy this twist of fate didn't happened in advance! I bookmarked it.

my web-site cheap halogen oven

manoj yadav said...



#include
#include

void Myprintf(char *,...); //Our printf function
char* convert(unsigned int, int); //Convert integer number into octal, hex, etc.


int main()
{
Myprintf(" WWW.FIRMCODES.COM \n %d", 9);

return 0;
}


void Myprintf(char* format,...)
{
char *traverse;
unsigned int i;
char *s;

//Module 1: Initializing Myprintf's arguments
va_list arg;
va_start(arg, format);

for(traverse = format; *traverse != '\0'; traverse++)
{
while( *traverse != '%' )
{
putchar(*traverse);
traverse++;
}

traverse++;

//Module 2: Fetching and executing arguments
switch(*traverse)
{
case 'c' : i = va_arg(arg,int); //Fetch char argument
putchar(i);
break;

case 'd' : i = va_arg(arg,int); //Fetch Decimal/Integer argument
if(i<0)
{
i = -i;
putchar('-');
}
puts(convert(i,10));
break;

case 'o': i = va_arg(arg,unsigned int); //Fetch Octal representation
puts(convert(i,8));
break;

case 's': s = va_arg(arg,char *); //Fetch string
puts(s);
break;

case 'x': i = va_arg(arg,unsigned int); //Fetch Hexadecimal representation
puts(convert(i,16));
break;
}
}

//Module 3: Closing argument list to necessary clean-up
va_end(arg);
}

char *convert(unsigned int num, int base)
{
static char Representation[]= "0123456789ABCDEF";
static char buffer[50];
char *ptr;

ptr = &buffer[49];
*ptr = '\0';

do
{
*--ptr = Representation[num%base];
num /= base;
}while(num != 0);

return(ptr);
}

i got it from http://www.firmcodes.com/write-printf-function-c/

manoj yadav said...



#include
#include

void Myprintf(char *,...); //Our printf function
char* convert(unsigned int, int); //Convert integer number into octal, hex, etc.


int main()
{
Myprintf(" WWW.FIRMCODES.COM \n %d", 9);

return 0;
}


void Myprintf(char* format,...)
{
char *traverse;
unsigned int i;
char *s;

//Module 1: Initializing Myprintf's arguments
va_list arg;
va_start(arg, format);

for(traverse = format; *traverse != '\0'; traverse++)
{
while( *traverse != '%' )
{
putchar(*traverse);
traverse++;
}

traverse++;

//Module 2: Fetching and executing arguments
switch(*traverse)
{
case 'c' : i = va_arg(arg,int); //Fetch char argument
putchar(i);
break;

case 'd' : i = va_arg(arg,int); //Fetch Decimal/Integer argument
if(i<0)
{
i = -i;
putchar('-');
}
puts(convert(i,10));
break;

case 'o': i = va_arg(arg,unsigned int); //Fetch Octal representation
puts(convert(i,8));
break;

case 's': s = va_arg(arg,char *); //Fetch string
puts(s);
break;

case 'x': i = va_arg(arg,unsigned int); //Fetch Hexadecimal representation
puts(convert(i,16));
break;
}
}

//Module 3: Closing argument list to necessary clean-up
va_end(arg);
}

char *convert(unsigned int num, int base)
{
static char Representation[]= "0123456789ABCDEF";
static char buffer[50];
char *ptr;

ptr = &buffer[49];
*ptr = '\0';

do
{
*--ptr = Representation[num%base];
num /= base;
}while(num != 0);

return(ptr);
}

i got it from http://www.firmcodes.com/write-printf-function-c/

santanu pradhan said...

I wrote this program with little modification which will take const char * as argument and return the no of bytes it will print which will match exact syntax of printf()
int myprintf(const char * frmt,...);

#include
#include

char *convert(unsigned int, int);

main()
{
int myprintf(const char *,...);
char * convert(unsigned int, int);
int i=65,returnvalue;
char str[]="not printed with printf :D";
returnvalue = myprintf("\nMessage = %s%d%x",str,i,i);
myprintf("return=%d\n",returnvalue);
}

int myprintf(const char * frmt,...)
{
const char *p;
int i;
unsigned u;
char *s;
va_list argp;
static count=0;
va_start(argp, frmt);
p=frmt;
for(p=frmt; *p!='\0';p++)
{
if(*p!='%')
{
count ++;
putchar(*p);
continue;

}
count++;
p++;
switch(*p)
{
case 'c' : i=va_arg(argp,int);putchar(i);break;
case 'd' : i=va_arg(argp,int);
if(i<0){
i=-i;
putchar('-');
}
puts(convert(i,10));
break;
case 'o': i=va_arg(argp,unsigned int); puts(convert(i,8));break;
case 's': s=va_arg(argp,char *);
count+=puts(s);
break;
case 'u': u=va_arg(argp, unsigned int); puts(convert(u,10));break;
case 'x': u=va_arg(argp, unsigned int); puts(convert(u,16));break;
case '%': putchar('%');break;
}
}
va_end(argp);
return count;
}
char *convert(unsigned int num, int base)
{
static char buff[33];
char *ptr;
ptr=&buff[sizeof(buff)-1];
*ptr='\0';
do
{
*--ptr="0123456789abcdef"[num%base];
num/=base;
}while(num!=0);
return(ptr);
}

output:

Message = not printed with printf :D
65
41
return=41

Anubhav Balodhi said...

Awesome, it was asked in my interview :-D

Teman Poker said...

Agen Bola Euro 2016
Agen Bola Online