From the course: C: Data Structures, Pointers, and File Systems
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Using printf() placeholders - C Tutorial
From the course: C: Data Structures, Pointers, and File Systems
Using printf() placeholders
- [Instructor] Perhaps the best way to understand the various width options for the printf functions placeholders, is to run some samples in code. This code outputs integer value one, two, three, using a clutch of different width formats. First at line eight comes the default placeholder %d. No width is specified. Lines 10 through 12 use eight as the width, and increase the value displayed for each printf statement. So line 11 it's a*10, line 12 it's a*100. Lines 14 through 16 duplicate these values, but left justified the output. See the minus sign at lines 14 through 16? Finally, a zero is added to the widths specifier at lines 18 through 20. Which pads zero's to the left of the number, filling the width of eight places. Build and run. Behold, the effect of all the conversion specifications on the values. In this exercise file, you see the %f placeholder with some width and truncation options. Line eight specifies no width. Line 10 specifies a width of 15 characters. Line 12…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Using single character I/O4m 4s
-
(Locked)
Testing characters2m 34s
-
(Locked)
Working with character conversions2m 17s
-
(Locked)
Understanding strings in C3m 3s
-
(Locked)
Fetching string input3m 18s
-
Sending string output2m 46s
-
(Locked)
Reviewing printf() placeholders3m 8s
-
(Locked)
Using printf() placeholders3m 36s
-
(Locked)
Exploring string functions3m 29s
-
(Locked)
Manipulating strings3m 53s
-
(Locked)
Avoiding string problems2m 27s
-
(Locked)
Challenge: String I/O and manipulation1m 46s
-
(Locked)
Solution: String I/O and manipulation2m 16s
-
-
-
-
-