Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save davidmerwin/7b45ef3f1017da3f60c8fa88477867dc to your computer and use it in GitHub Desktop.
Save davidmerwin/7b45ef3f1017da3f60c8fa88477867dc to your computer and use it in GitHub Desktop.
This program prints a series of lines that demonstrate the use of single quotes, double quotes, backslashes, and a tab. https://davidmerwin.pieces.cloud/?p=7c7b4fb26e

Outputting Special Characters in C Program

Preview:
/************************************************
* Name: David Merwin
* Date Created: 2023
*
* Description: This program demonstrates the use
*              of escape sequences in C to print
*              special characters.
*************************************************/
#include <stdio.h>

int main(void) {
    
    // Outputs a message to the user
    printf("This program demonstrates the use of escape sequences in C to print special characters:\n");
    
    // Outputs single quotes
    printf("Single quotes: '\n");
    
    // Outputs double quotes
    printf("Double quotes: \"\n");
    
    // Outputs backslashes
    printf("Backslashes: \\ \n");
    
    // Outputs a tab
    printf("Tab: \t and uses a tab\n");
    
    return 0;
}
Associated Context
Type Code Snippet ( .c )
Associated Tags tabulation Backslashes Double Strings SDK Use Cases backslashes Single Strings main function C programming printf function Tab Usage Program Output Main Function program execution output formatting double quotes Console Output single quotes Program Execution escape characters
💡 Smart Description This program outputs two quotes, double quotes, backslashes, and tab. It then prints the result to the console with a single line of spaces or multiple tabs in an interactive shell.
This program prints a series of lines that demonstrate the use of single quotes, double quotes, backslashes, and a tab.
🔎 Suggested Searches program to print single quotes and double quotes
How to use backslashes in program output
Printing tabs using printf() method
Using tab\n program with multiple quotes
C program printing single quotes, double quotes, backslashes, and tabs
C program with printf statements for single quotes, double quotes, backslashes, and tabs
C program outputting single quotes, double quotes, backslashes, and tabs
C program example with printf statements for special characters
C program using escape sequences for single quotes, double quotes, backslashes, and tabs
Related Links https://www.learn-c.org/en/Welcome
https://www.programiz.com/c-programming/c-input-output
https://www.programiz.com/c-programming
https://www.w3schools.in/c-tutorial/
https://www.learn-c.org/
https://www.geeksforgeeks.org/c-programming-language/
https://www.tutorialspoint.com/c_standard_library/c_function_printf.htm
Related People David Merwin
Sensitive Information No Sensitive Information Detected
Shareable Link https://davidmerwin.pieces.cloud/?p=7c7b4fb26e
@davidmerwin
Copy link
Author

Screenshot 2023-09-22 at 3 06 59 PM

@davidmerwin
Copy link
Author

Screenshot 2023-09-22 at 3 11 34 PM

@davidmerwin
Copy link
Author

/*
2. Write a program that uses the appropriate escape sequences to output the following:

This program outputs:
'Single quotes'
"Double quotes"
\Backslashes
and uses a tab
*/

/************************************************

  • Name: David Merwin
  • Date Created: 2023
  • Description: This program demonstrates the use
  •          of escape sequences in C to print
    
  •          special characters.
    

*************************************************/
#include <stdio.h>

int main(void) {

// Outputs a message to the user
printf("This program demonstrates the use of escape sequences in C to print special characters:\n");

// Outputs single quotes
printf("Single quotes: '\n");

// Outputs double quotes
printf("Double quotes: \"\n");

// Outputs backslashes
printf("Backslashes: \\ \n");

// Outputs a tab
printf("Tab: \t and uses a tab\n");

return 0;

}

/*
Submission Requirements:
Provide a header comment for every program in this course similar to:
/************************************************
* filename: toes.c
* Exercise: Module 1, Exercise 2
* Name: John Doe
* Date Created: January 1, 2015
*
* Description: This program calculates ......
************************************************/
/

Use "standard" C formatting and style (see Listing 2.2).
Insert blank lines to separate "sections."
Indent statements within a block of code.
Put calculations in a separate statement (not embedded in printf).
Add comments within the code, especially ALL calculations.
Incorporate a good, clean, informative, friendly user interface.
Display a brief program description to the user.
Insert blank lines where appropriate for readability.
Clearly identify what the output represents to the user.
Provide example user inputs if necessary.
All programs must use "int main()" with "return 0;" to be ANSI C compliant.
Complete the programming exercises and submit your answers into the drop box at the end of this module by
attaching your .c program files that you compiled and executed by clicking 'submit' on the right side of the window.
Each program should be a separate attachment so the Drop Box for the Module 1 Programming Assignment should have five files attached, each with a .c file extension.
The file names of attached programs should match the file name identified in the header comments of each program.

*/

https://davidmerwin.pieces.cloud/?p=7c7b4fb26e

https://gist.github.com/7b45ef3f1017da3f60c8fa88477867dc

@davidmerwin
Copy link
Author

Keyword/Concept Key Idea Key Term Meaning Hardware Used How Hardware Interacts Context
#include Directive Preprocessor $\begin{array}{l}\text { A command that tells the } \\text { compiler to include a } \\text { library or a header file. }\end{array}$ Disk/Storage $\begin{array}{l}\text { Loads the content of the } \\text { specified file from storage } \\text { into RAM for execution. }\end{array}$ $\begin{array}{l}\text { Used at the start of the } \\text { program to include } \\text { necessary libraries, here } \\text { stdio.h for basic I/O } \\text { operations. }\end{array}$
〈stdio.h〉 Header File Standard I/O $\begin{array}{l}\text { A file that contains } \\text { declaration of } \mathrm{I} O \mathrm{O} \\text { functions. }\end{array}$ Disk/Storage $\begin{array}{l}\text { Loads the file into RAM } \\text { during program execution. }\end{array}$ $\begin{array}{l}\text { Included in most C } \\text { programs for input/output } \\text { operations. }\end{array}$
printf Function Output $\begin{array}{l}\text { Used for output on } \\text { the console. }\end{array}$ CPU, RAM, Monitor $\begin{array}{l}\mathrm{CPU} \text { executes the function, } \\text { retrieves the data from } \\text { RAM, and outputs it on the } \\text { monitor. }\end{array}$ $\begin{array}{l}\text { In this code, it's used to } \\text { display different lines of } \\text { text and special characters } \\text { on the console. }\end{array}$
In Escape sequence Newline Inserts a new line Monitor $\begin{array}{l}\text { The text after this is } \\text { displayed on the new line } \\text { on the monitor output. }\end{array}$ $\begin{array}{l}\text { Used in the printf } \\text { statement for line-breaks. }\end{array}$
$\prime^{\prime}$ Escape sequence Single quote Prints a single quote. Monitor $\begin{array}{l}\text { The single quote is } \\text { displayed on the monitor } \\text { output. }\end{array}$ $\begin{array}{l}\text { Used in printf statement to } \\text { display a single quote. }\end{array}$
$\backslash "$ Escape sequence Double quotes Prints double quotes. Monitor $\begin{array}{l}\text { The double quotes are } \\text { displayed on the monitor } \\text { output. }\end{array}$ $\begin{array}{l}\text { Used in the printf } \\text { statement to display a } \\text { double quote. }\end{array}$
11 Escape sequence Backslash Prints a backslash. Monitor $\begin{array}{l}\text { The backslash is displayed } \\text { on the monitor output. }\end{array}$ $\begin{array}{l}\text { Used in the printf } \\text { statement to display a } \\text { backslash. }\end{array}$
It Escape sequence Horizontal tab Inserts a tab space Monitor $\begin{array}{l}\text { The text after this is } \\text { displayed with a tab space } \\text { on the monitor output. }\end{array}$ $\begin{array}{l}\text { Used in the printf } \\text { statement for adding } \\text { horizontal space. }\end{array}$
return Keyword Function Exit $\begin{array}{l}\text { Indicates the end of } \\text { a function. }\end{array}$ $\mathrm{CPU}$ $\begin{array}{l}\text { Breaks the function } \\text { execution and moves } \\text { control back to the calling } \\text { function or OS. }\end{array}$ $\begin{array}{l}\text { Used in main }() \text { to indicate } \\text { successful termination of } \\text { the program. }\end{array}$
main Function Program Entry Point $\begin{array}{l}\text { The function where } \\text { execution begins. }\end{array}$ $\mathrm{CPU}$ $\begin{array}{l}\mathrm{CPU} \text { starts the execution } \\text { from main function. }\end{array}$ $\begin{array}{l}\text { Every } C \text { program begins } \\text { from the main function. }\end{array}$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment