C 03: Printing to stdout and stderr using printf() and fprintf()
96 views
0

 Published On Feb 18, 2024

We'll go over how to use printf() and fprintf() functions to generate useful and attractive reports including strings, integers, floats and doubles on Windows and Linux.

You will also see how to generate random test data to test your report after you have designed the report. Something you'll definitely do in your career.

C 02: Strings in C (Previous):    • C 02: Strings in C  
C 04: Advanced printf() to display currency characters in your report:    • C 04: Advanced Printf - Currency Char...  

C++ 12: Formatting your data effectively using iostream and iomanip:    • C++ 12  Interactivity - Formatting Yo...  

00:00 Introduction to Printf
01:18 Review of puts()
03:35 Printing strings with printf()
08:32 Printing integers with printf()
14:01 Printing float and doubles with printf()
19:15 Creating a nicely formatted report with printf()
42:17 Printing to stderr using fprintf() on Linux
46:25 Printing to stderr using fprintf() on Windows

Print codes/data types for use with printf():
- String: %s
- Unsigned Integers: %d
In octal format: %o
In hexadecimal lower case format: %x
In hexadecimal upper case format: %X
- Floating Point Numbers: %f
- Specifying the number of fractional digits: .n
Example: printf("%.2f", someNumber);
- Scientific Notation: %e (lower case e), %E (upper case E)
- Width of the data to print: %nType
Example printf("%12d", someNumber);
- Left justification: %-nType
Example printf("%-12d", someNumber);
- Printing the percent symbol: %%

show more

Share/Embed