0

is printf capable of replacing things in a string.. faster than some other function that would have to locate and replace things in a string ?

const char * s = "--%s--%s--%s--";
printf(s, "aaa", "bbb", "ccc");

if it was possible to visualize how printf() was locating and replacing the %s strings in the string..

what would it look like ?

circle
  • 1
  • 1
  • 1
    This one [Code for printf function in C](https://stackoverflow.com/questions/4867229/code-for-printf-function-in-c) ? – LEQADA Jul 17 '17 at 19:17
  • 2
    @circle `printf(s, "aaa", "bbb", "ccc");` is not replacing things in a string. It is simply printing. No _strings_ changed. The output is not a _string_ (Hint: no null character). Add more detail to bring clarity to the post. – chux - Reinstate Monica Jul 17 '17 at 19:28
  • 2
    Fundamentally, `printf()` et al copy characters from the format to the output until a `%` is encountered, then switch gears to process the conversion specification, repeating the process until the end of the format string is reached (or an error occurs). For formatting strings, look at [`snprintf()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/snprintf.html) and relatives. Theoretically, if the format string uses the POSIX `n$` notation, the `printf()` function should validate the whole format before processing because of the constraints on needing `1$`, `2$`, …, `n$`. – Jonathan Leffler Jul 17 '17 at 19:37

0 Answers0