c - Implementation of printf -


can please explain me implementation of printf prints string correctly?

version 1:

printf(const char * s) {      while(*s != '\0') {           write(s, 1, f);           s++;      } } 

version 2:

printf(const char *s) {      write(s, strlen(s), f); } 

both print "a string correctly". print given string in argument correctly.

if question better implementation suggest depends on implementation of write.

option 1 slower if write call has large enough overhead or can buffer characters before committing write.

option 2 slower if write unoptimized. example puts character character on serial connection. here pay additional iteration of string strlen.

note write call takes file descriptor first argument, not last.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -