Finally, we can format a single character with the c type conversion, as follows:
printf("Character output\n");
printf("%%c [%c] character\n",aChar);
printf("%%10c [%10c] character right-aligned, field=10\n",aChar);
printf("%%-10c [%-10c] character left-aligned, field=10\n\n",aChar);
First, a single character is printed. Then, it is right-aligned in a field of 10. Finally, it is left-aligned in a field of 10.
Enter these code snippets into character_string.c. Compile and run the program. You should see something similar to the following output:
Notice how the alignment, minimum field width, and precision modifiers behave for strings and characters as they do for integers and doubles.
This completes our exploration of formatted output. With these programs, you can continue with your own exploration.