Formatting output
This presentation is the property of its rightful owner.
Sponsored Links
1 / 18

Formatting Output PowerPoint PPT Presentation


  • 62 Views
  • Uploaded on
  • Presentation posted in: General

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”); }. Output. Welcome toLondon! How do we Jump two lines? It will rain tomorrow.

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Formatting output

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”);

}


Output

Output

Welcome toLondon!

How do we

Jump

two lines?

It will rain

tomorrow


What if i want to print a or

What if I want to print a \ or “

printf(“How to print a \\ backslash\n”);

printf(“How to print a \” quote\n”);


C string literals

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”);


More escape sequences 2 4

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


Character escape sequences

Character Escape Sequences

  • \0Null character

  • \aAlert/bell

  • \nNew Line

  • \0dddOctal constant

  • \xdddHexadecimal constant

  • \XdddHexadecimal constant


Character escape sequences1

Character Escape Sequences

  • \\Display a backslash

  • \’Display a single quote

  • \”Display a double quote

  • \%Display a percent character

  • \?Display a question mark


Review of chapter 2

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


Let s look at l2 5 c

Let’s look at L2_5.c


What are the important features of a c program

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


More c program features

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.


What is debugging

What is debugging

  • Fixing problems that cause your program to behave unexpectedly.

  • 3 types of programming errors

    • Syntax errors

    • Run-time errors

    • Logic errors


Syntax errors

Syntax Errors

  • Violation of C “grammer” rules

  • Typographical mistakes

  • Compile time errors


Run time errors

Run-time errors

  • Semantic errors (errors of meaning)

  • Not detected by compiler

  • Violation of the rules during execution of your program


Logic errors

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?


How to reduce programming errors

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)


How to debug your program

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


Lets do a debugging example

Lets do a debugging example

  • Program 2.2 Debugging (Page 64)


  • Login