C Program Workshop - C Programming - Lecture Slides, Slides of Computer Science

These are the Lecture Slides of C Programming which includes Sscanf() Function, Snprintf() Function, Converts String, Floating Point Value, Searches for First Occurrence, Number of Characters, Token Separators, Value of Zero Means etc. Key important ponts are: C Program Workshop, Workshop Features, Bins for Parts and Supplies, Operating Procedures, Transformed Data, Current Data, Program Entrances and Exits, Constants and Variables, Data Types

Typology: Slides

2012/2013

Uploaded on 03/21/2013

dheeraj
dheeraj 🇮🇳

5

(4)

101 documents

1 / 13

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
THE C Program Workshop
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download C Program Workshop - C Programming - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

THE C Program Workshop

Workshop Features

Door for expected results to go out

Door for requests to go in

Door for unexpected results to go out

Bins for parts and supplies

Various tools

WORKSHOP
X Y Z
A B C D

Instructions and operating procedures

Communication with other shops

C Program Entrances and Exits

STANDARD

OUT (stdout)

STANDARD

IN (stdin)

STANDARD

ERROR (stderr)

Constants and variables

Operations and functions

main

X Y Z
A B C D

Instructions and operating procedures

File and Device Input/Output

Data Types

• Integers ( int )

• Numbers with decimal points ( float )

• Characters ( char )

• Words and Phrases (ex. char phrase[10] )

• Tables (ex. int values[10] , float matrix[20][30] )

• Records (ex. struct myRecordType )

Simple Operations

• Storage (=)

• Addition (+)

• Subtraction (-)

• Multiplication (*)

• Division (/)

• Modulo (%)

• Comparison (==, !=, <, <=, >, >=)

Instructions and Decisions

  • variableLocation = expression
    • Ex. count = 17 * MAX_LOOPS;
  • if (Boolean condition) statement else statement
    • Ex. if (numberIsValid) count++; else count--;
  • while (Boolean condition) statement
    • Ex. while (count > MAX_LOOPS) count = count – 5;
  • for (statement; condition; statement) statement
    • Ex. for (i = 0; i < size; i++) printf(“%d\n”, table[i]);

Standard C Library Functions

• Standard Input and Output:

  • printf, scanf, getchar, gets

• Conversion of Data:

  • isalpha, isdigit, tolower, toupper

• Math:

  • sin, cos, tan, sqrt, log, exp

• Working with Files:

  • fopen, fclose, fscanf, fprintf, fgets

Example Program - C Source Code

int main(void) { int theCheckNbr; char theAccount; char theTaxCode; float theAmount; float theBalance; theBalance = 2391.52; printf("Ck Nbr Acct Tax Amount Balance\n"); printf("------ ---- --- ------ -------\n"); theCheckNbr = 234; theAccount = ‘B'; theTaxCode = ‘Z'; theAmount = 34.56; theBalance = theBalance - theAmount; printf("%6d %2c %2c %6.2f %7.2f\n", theCheckNbr, theAccount, theTaxCode, theAmount, theBalance); return 0; } // End main

Example Program Exercise

  • Using the current pattern of statements in the

program, add the source code to display the last two

lines of the report shown below

  • Also, change the order of the report columns

Ck Nbr Amount Acct Balance Tax


234 34.56 B 2356.96 Z 235 192.73 T 2164.23 W 236 75.00 G 2089.23 X