1 / 18

Formatting Output

Formatting Output. #include &lt;stdio.h&gt; void main (void) { printf(“Welcome to”); printf(“London!”); printf(“<br>How do we<br>jump<br><br>two lines?<br>”); printf(“<br>”); printf(“It will rain<br>tomorrow<br>”); }. Output . Welcome toLondon! How do we Jump two lines? It will rain tomorrow.

pascha
Download Presentation

Formatting Output

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Formatting Output #include <stdio.h> void main (void) { printf(“Welcome to”); printf(“London!”); printf(“\nHow do we\njump\n\ntwo lines?\n”); printf(“\n”); printf(“It will rain\ntomorrow\n”); }

  2. Output Welcome toLondon! How do we Jump two lines? It will rain tomorrow

  3. What if I want to print a \ or “ printf(“How to print a \\ backslash\n”); printf(“How to print a \” quote\n”);

  4. C String Literals • Anything inside double quotes • Use \ to break string literal across a line printf(“This shows how to break \ a string literal across lines\n”); printf(“This shows how to break “ “a string literal across lines\n”);

  5. More Escape Sequences (2.4) • Consist of a backslash followed by a letter, symbol, or combination of digits • Represents a character that has special meaning or specifies an action

  6. Character Escape Sequences • \0 Null character • \a Alert/bell • \n New Line • \0ddd Octal constant • \xddd Hexadecimal constant • \Xddd Hexadecimal constant

  7. Character Escape Sequences • \\ Display a backslash • \’ Display a single quote • \” Display a double quote • \% Display a percent character • \? Display a question mark

  8. Review of Chapter 2 • Basic structure of a C program • Writing comments • Using character escape sequences • Displaying special characters • C string literals • Basic debugging techniques

  9. Let’s look at L2_5.c

  10. What are the important features of a C program • The main function name must be main • The prog body must start with { • The prog body must end with } • A C statement must end with ; • A C statement is case sensitive • A C statement is location insensitive

  11. More C program features • In general, it is OK to add blank(s) between tokens in a C statement but it is not OK to add blank(s) within a token • C uses character escape sequencs for special characters and action • Make your comments stand out. Do not hide them.

  12. What is debugging • Fixing problems that cause your program to behave unexpectedly. • 3 types of programming errors • Syntax errors • Run-time errors • Logic errors

  13. Syntax Errors • Violation of C “grammer” rules • Typographical mistakes • Compile time errors

  14. Run-time errors • Semantic errors (errors of meaning) • Not detected by compiler • Violation of the rules during execution of your program

  15. Logic errors • Most difficult errors to find • Program compiles and runs fine it just does not produce the correct results. • Is the input data correct?

  16. How to reduce programming errors • Writing your program neatly • Adding blank lines at natural locations • Lining up your opening and closing braces • Add useful comments • Build your program in sections (layers)

  17. How to debug your program • Think about debugging up front before you write your program • Write your program in layers • Look for the obvious syntax errors • Correct function names • Statement termination • Are my parentheses and braces matched up

  18. Lets do a debugging example • Program 2.2 Debugging (Page 64)

More Related