Aspects


vs


Home Page
About Us

Printf

`printf` is a common function for formatted output

Strlen

A standard C function that returns the length of a string.



Others

Example

Note strlen only works on null terminated strings and will cause undefined behaviour if the string is not null terminated;printf also needs more error checking which can be found on the man page

from question  

What is the best alternative to strncpy()?

Also though printf interprets its argument as a format string - what it ends up printing can be a very different length from the string it was given if it inserts values into placeholders;as bub said part of the difference is that strlen doesn t print the string just returns its length

from question  

Why do we use 'strlen()' if 'printf()' itself returns the length of the string?

You should use printf with the real length of buffer or at least handle the size limit yourself inside the loop;in case strlen str is larger than buffer s size 2

from question  

Convert byte array / char array to hexidecimal string in C

This might be causing the printf to not print the string;please do remember that strlen gives length without the 0

from question  

Printf Not Working in Ubuntu

Strlen is fast alloca is fast copying the string up to the first n is fast puts is faster than printf but is is most likely far slower than all three operations mentioned before together

from question  

Printing a string due to a new line

Back to Home
Data comes from Stack Exchange with CC-BY-SA-4.0