You're using
printf
to print a singlechar
:printf("%c", aux[j]);
printf
is a very handy tool to format output, but it carries quite a bit of overhead with it – not something you want to call over and over without a good reason. A much more efficient way to print a singlechar
tostdout
would be:putchar(aux[j]);
Or, instead of looping over the string to print it character-by-character, you can printfprint the whole thing with just one function call:
puts(aux);
(Note that
puts
prints an additional newline character at the end of the string. If you want to avoid that, usefputs(aux, stdout)
instead.)puts
andfputs
require the string (aux
) to be terminated by a NUL-character ('\0'
), which it isn't in your program. If you want to print a character sequence of known length (but possibly without such a terminator character), you can use:fwrite(aux, 1, strlen(n), stdout);
You can also use
puts
orfputs
to print all the string literals in your program with less overhead, e. g.puts("\nWelcome to the super, duper string inverter!");
instead of
printf("\nWelcome to the super, duper string inverter!\n");
Now you don't even need to worry about
%
characters being interpreted as format descriptors.You can concatenate string literals that are printed right after each other to avoid the overhead of additional buffering and I/O locking and unlocking:
fputs("Included with the super mojo from the string inverter, this is the result: ", stdout);
If you don't like long string literals you can break them into multiple parts:
fputs("Included with the super mojo from the string inverter, " "this is the result: ", stdout);
produces exactly the same syntax tree and binary code as the source code just before.