Yashvant Kanetkar

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Yashvant Kanetkar as PDF for free.

More details

  • Words: 8,329
  • Pages: 227
Why C? .) C

is simple

.) C

is fast

+ C is small

+ C offers better interaction wlth hardware

Historical Development of C 1960 International Committee

Mach~neOriented , Ex. Assembly,

KlClT I

C I Lecture 1

Ex. Basic, Fortran, Pascal,Cobot

I

In The Beqinnina

...

Alphabets, Dlglts

Symbols Dlgltr, SP. Alphabets,

Words, Numbers

Constants. Variables,

Alphabets, Diaits,

-

Constants and Variables

KlClT I C i Lecture I

Character1

1

String

1I

Structure Union Enurn etc.

i

lnteqer Constants

.

Rules:

/-

1. No decimal point.

1

a

ic

2. May be +vs or -ve. Default: +vs

3. No comma or

4

*

spaces 4. Valid Range: -32768 to +32767

Real Constants EX. 427.62

+24.297

.

-0.00254

Rules: 1. Must contain a decimal point. 2. May be +ve or -ve. Default: +ve

3. No comma or spaces. 4. Valid Range: - 3 . 4 ~t030 to +3.4 x

KlClT I C 1 Lecture 1

I

]

I

V

+

m

@&=J

many types? As many as the types of constants.

HOW

Is it necessary to identify types?

7 Memory y=4

z=x+y print z

z

+ An entity whose value can change .) A name given to a location in

memory

KlClT I C I Lecture 1

1 I

--

Integer Constant

3.0 Real Constant $3' ---t Character Constant a -7 b - ? c + ?

C's Wav of ldentifyinq Variables int a a=3

float b b = 3.0

char c c = '3'

$h pt.3 @*tdbin$h t

Rules for Buildinq Variable Names First character must be an alphabet, rest can be . @ h a t s , or underscores.

@a,

Ex, pop98

a

r

si-int

sl-int

Length <= 8 (Us ally)

Usl-~nt

m

No commas or spaces

I-p

Variable names are Ex. abc ABC Abc aBc AbC

KICIT I C I Lecture 1

C Keywords .)

How many? What are Keywords?

I)

What are Reserved words?

Would This Work? integer a El ink '

1

real b

11db

character c

~ h &c

And How About This... int f l o a e float = 3

char float = 3.1

Where Uo We Stand?

P' 91

Alphabets, Digits, Sp. Symbols

~ o n s t m t sVariables. , Keywords

51

Statements or Instructions

KlClT I C I Lecture I

1

The First C Proclram

float p, r, si

int n p = 4000.50 n=3

r=15.5 sl=p*n*rll00

Tip: All variables must be declared.

1

float p, r, sI int n p = 1000.50 n=3

r=15.5 sl=p'n+r1100 printf ( "%fl, si )

KlClT I C I Lecture I

*fim

Terminoloay Matters ()

Parentheses

{ ) Braces [ 1 Brackets

General Form of ~ r i n t f ( printf ( "format string", list of variables )

'I b can . contain , <+ -

,

-

5

%i integer

4,L

-

i.?!

-

%c character

%f float

Ex, prlntf ( "%f %I %f %fl,p, n, r, si )

) tlw

awd ulric,bb in mdQ/r d dC Q I & & ~ -

I I amStatement Terminators p, a boy I go to school

noat int n

r, si

-

float p, r, si ; int n ;

c t a t y ~t erminato)

: colon

; semicolon

KlCIT I C I Lecture 1

Free borm Lanauaae float p, r, si ; int n ; is same as

9 Q

floatp,r,si; intn;

What I o Execute ,-main(

n=3: r=15.5; si=p+n'rIlOO: printf "%fl, si ) ;

maln( )

e{

float p, r, si ; Int n ; . p=IOOO.SO;n = 3 ; r = 1 5 . 5 ;

si=p*n'rllOO; prlntf "OhP', si ) ;

I!)

KlClf I C I Lecture I

I' Calculation of slrnpltr Interest ' I main( ) { float p, r, si ; Int n ; p=1000.50:n=3;r=15.5; si=p'n'rllOO; printf ( ""/of', si ) ;

& &'

1

Any number of comments anywhere I' formula ' 1 si = p



Multiline comments

......*I

n * r 1100 ; I*

-

r .............................

............................... 'I

Nested comments

-

r ..............I* .......' I ........' I

A I' Calculation of simple interest *I main( ) { float p, r, sl ; int n ; prtntf ( "Enter values of p, n and r scanf j "%f %i%t", sl=p'n*r1100; printf "%f", sl ) ;

) ,

1

KlClT I C I Lecture I

");

1

Forms of Real Constants

-

427.62 ----+ 4.2762E2 +24.295 -4 2.4295~1 -0.00254 -2.54e.3

Fractional Form

Exponential Form

==a -3

-.,

CI

4.2762: E&T -

->

Exponent

Mantissa

Character Constants '3'

'm'

Rule : A single character enclosed

within a pair of '

'.

Are Thev OK?

'Nagpu-

I>cj

C Variables

Integer

Polnter

Character

Strlng Structure Unlon ' Enum etc.

KlClT I C I Lecture I

1

.k Turbo C k QuickC

* Microsoft C j,

Artech C

Jr Zortech C tattlce C .rt Watcom C 3r GreenLeaf C

*

* Vitamin C

1 J

l ntesrated Develooment Environment --cde~k?m n

r*

4p

Editor and Com~iler Edltor

-

Helps In typing I edltlng of a program

* Compiler - Converts C language program to machine language program

KlClT I C I Lecture 2

ommands

Editin Cursor Movement

Daletlon

+ Up Arrow 4 Down Arrow + Rlght Arrow +Len Arrow

Backspace Ctrl+T CtrltY

Home

End

PgUp

PgDn

Computers are fun

b o b

*+ ir\.ln\ Some ~ hrub. k More Commands

~lsinhciid

-6'

;?$ Perm

* '

Save As Exit

' Do* Shell

Tempora

.-]

CtrltFg Compile AlttF5 OutputAIi +F3 CIosm wlndow

RLt t X

e~i*

Tlp: Use rneanlngful filenames. Ex. CHtPR1.C

1

lnterchanclina Contents of Two ~ariab1.s maln( )

I

h

~ h e + h f m d+&SW

Int c.d: . .

prtnti ( "Enter values of c and d" ) ;

KICIT I C I Lecture 2

d

I

(9j

~P,D/

~wmh ,

f i b o b +Fvr~v q 1i ~ h t

lnterchanaina Contents of Two Variables e mar( )

I

Inlc,d,t; printf ( "Enter values of c and d" 1 ;

rcsntl "XI%I",LC,&d ) ; t-c;

C

~1~~

dwt:

c

1

One More Way c=c+d; d=c-d; c=c.d;

:

Sum of Diaits main( ) Int n ; printf ( "Enter a flve dlnlt no." ) ;

.....0.

I

KIClT I C I Lecture 2

d

t

d

t

mmm

.-

prlnU( "XI XI". c, d )

t

BBLl c d t

c-d;

prlntf ( "XI Xi", c. d ) ;

d

Calculations

: 2691 - Division I - Modular division 2691 3 % 10 1 7 3 26913 1 10

I O ~ Z 6 ~ 1 3 / 2 6 9 ~

The Whole Picture main( )

n

s =dl +dZ+d3+d4+d5; printf ( "%I", s ) ;

0"-'

&*

i modulus i R e a v Useful *

*

Leap year or not Odd 1 Even Prime or not -s

KiClT I C I Lecture 2

diw&bk by Ior ib$.

1

Where Are We .... Alphabets, Digits, Sp.Symbols

1Constants, Variables, Keyword& I

J


C Statements I Instructiong

*

Type Declaratlon lnstructlon Ex. Int i, 1, k : float a, b, c ; char ch ;

Tvae Declaration, A few Subtleties Int a ; a-5;

1s same as

2

int a = 5 ;

*inta=S,b=lO, c=a+ba5Y*2: Here order Is Important

KlClT I C I Lecture 2

Is This Ok? It. tnt a, b, e, d ;

a=b=c=d=5;

&??I

C~3tatementsllnstructions k Type Declaration Instructions

* Arithmetic Instructions Ex.

s=dl+d2*d3;

si=j*n"r1100; c=5.019'f-32; +, -,', I , %

-

Arlthrnetic Operators For exponentlatlon Use pow( )

-

Arithmetic Instructions. A Few Small Issues

KlClT I C I Lecture 2

T V Dof~ Arithmetic lnstruction~ +

Integer mode Al

* RmtmoQo Al

+ Mixad modo AJ Ex. i n t m = 3 , b * 4 , c ; c-agb+5%8-b+l4;

Leaal Arithmetic Operations 1

Onerandl float

I

Omrand2 float

Tty This Int a ; a=512; ao5.012; 4 Q a=512.0; - 2 a = 5.0 12.0 ; + ar215; -0 a82.015; --*D a 2 1 5.0 ; ---+ @ a = 2.0 I 5.0 ; L 0

2

KlClT I C I Lecture 2

1

Result float

I

Try This float a ;

float c, f

= 21 2.0 ;

KlClT I C I Lecture 2

r" G % P - @ b ~ - ihn t

vanicJda

C Instructions

* Type Declaration Instructions

*

Arithmetic lnstrudlonr

* Input I Output Instructions printf() scanf( )

- Output - Input

General Form of prinffLS prlntf ( "lormat string", list of rarlabler ) ; prlntf I "Enter values of c and d" ) ; List d varlab4es is optional.

4

printf ( "%I %i %i",a, 3 9 2 + 8 % 3 ) ; -/ ~l~tcancontalnvarlables,cons~nts or expressions.

printi( ) prlntf ("format atrlr~g",llrt of varlmbl~s) ;

a

KlClT I C I Lecture 2

I

1

Numberina Svstems Declrnal Octal Hsxadsclmal (0.S)

(0.7)

0

0 I

t

(0.W.A-F) 0

Binary (0.1) 0

I

1

10

1Wo

IW

1W

...

FF 100

....

Conversr on^ Oeel 473

4~1O2+7*10~+3*IOP~473

krrr 11 d e c l m a L l * ~ g ~ + l ~ l ~=~17 !

Bloaryl? - $ * 2 1 + 1 ' 2 0

\L*

.

\*a' + \ A % '

More Conversions

It=~ a i n d P / v .

KlClT I C I Lecture 2

=3

q

-.-

q0d = &JpJmd P ~ ~ v ~ v R L P ~ % O =& & q w l i v M

Xr=

gB y

~

~

~

-

\n Newllne Irr \t -Tab $r prlntf ( '%d\n%d\t%dt', 10,20,30 )

:

v Other Characters

* prlntf ( ''Enter valuer of c and d" ) ; It prlntf ( "Hello" ) ; g p r l n " ( "\nSlmple Interest rn n \

KlClT I C I Lecture 2

-

~

- hkaq.bhd

p r ~ n t f l Makes ) It Handy

$r

~

Rs. %f', $1) ;

-3

-

e

d

t

u

r

u

I

.*scanf ( "format string", list of variables j ; scanf ( "%d %f %c", &l,&a, bch ) ;

*

C Instructions

KlClT I C I Lecture 2

+ Type Declaratlon lnstructlons + Arithmetic lnstructlons + Input 1 Output Instructions

* Control Instructions

Control Instructions + +

What are they? Control the sequence of execution of lnstructtons What different types? Sequence Decision ~e~etition(hp> Case

-

-

int .....; float ...... ;

...... ......

prlrltf ( ); scanf ( ); a = .... ; b = ....; prlntf (: .......);

1

: CI Is the default CI I I 1 ~ i pSequence

KlClT I C I Lecture 3

I*Calculatlon of total expenses *I main( )

{ lnt qty ; float prlce ; printf ( "Enter quantity and prfce" ) ; scanf ( "%d%f", &qty, &price ) ;

I' Calculatlon of total expenses ' I

main( ) {

lnt qty ; float price ; Int dis ; float iotexp ;

dis = 0 ;

-

totexp = qty ' price qty * price ' dis I100 ; printf ( "Total expenses = Rs %f", totexp 1 ;

1

Tips. + if, else Keywords + General form: if ( condltlon )

statement1 ; else statement2 ; + Cond. is usuallv built uslng <,

a==-

2

KlClT I C I Lecture 3

>, c=, >=, = =, I=

(@ Would This Work? Int a = 5, b = 4, c, d ; Jprlntf ( "Xd", a + b ) ; / J prlntf ( "%d", a r = b ) :& J

/~=a'b; j ' p r l n t f ( "Y,d", c j

Tip:

-

. )

. & .----

:

Condition -True - Replaced by 1 Condition False Replaced by 0

-

-

Int a ; printf ( "%d", a ) Tip: Unless specifleally initialised a variable contains abarbage value.

r

Calculation of Total Expenses *I

main( ) {

Int qty ; float price ; int dls = 0 ; float totexp ;

If qty >= 1000) dis= 1 0 ; totexp = qty " price qty price * dls 1 100 ; prlntf ( "Total expenses = Rs %f",totexp ) ;

-

1 Tip: else block is optional

KICIT 1 C I Lecture 3

( - -' float bs, hra, ca, da, 0s ; prlntl( "Entrr bask walary" ; *cant ( "W',&bs ) ;

ca=bs*IZ1100; else

-

If block

hn-br'lSI100;

ea 200 ; ga bs + hta da + printf ( "Grolr salary

balongs to

= Ra. sf',~r ) :

k

t bm. hta, ca, da, gs ;

-

dam

pdntli "Entar bmlc salary" ) : mcanf (*%r',&bs ) :

6 )

...;bra= ...; c a m . ..;

else

a

'

Y )

dam

... ;bra- ... ; c # - , , , ;

gs=bs+d*+hra+ca;

prlntl( "Grorr firlary

Rs Xf", gs )

1

:

One More Form If ( condllbn ) I

\

ITlp: - Dafault scopa of If and o I m Ia'only the next strtmrnent after tham.

-To ovorrlde *I#dotaust scope use { )

KlClT I C I Lecture 3

w

Leap Year or Nof

Int y : prlntf ( "Enter year" ) ; scanf ( "%d", By J ;

Laap

Leap

rna\n( ) (

Nwted If-else

... !f(y~.~oa--aj

lf(y%40Om-0)

(

prlntf ( "Lmap" 1 ;

11*1

prlntt ( "Not l e a p "

1

69

olio prlnff ( "Not Leap* ) ;

1

First Day of Anv Year main(

1

(

Int y ; prlntf ( "Enter year" ) ;

scanf ( "%d", &y )

.. .

KlClT I C I Lecture 3

;ax>

11111

dMonday

8t $11

<' Monday

151111

C~Manday

221 11 1

Monday

281 11 1

Mandry

... ... ...

1111 1 to3111Zl 1887

i ~ i t i v ~C@ e

scanf ( "Xd". &y ) : normaldays = ( y 1 ) 365 ; leapd~ys-(y-1)14-(y-1)/100+(y-1)/400;

30

totaldays = normaldays + leapdayr firstday * toUldays % 7 : If ( firstday 0) prlntf ( "Monday" ) ;

--

4

%-OAoo+'&

7 $7

't-C%-\))~oo 3

h.

~00iod t

2000,

cy-Q&

c w d i n q T-otd no. qj d&,

main( ) {

tnt y, firstday, leapdays ;

Long Int normaldays, totaldays ; ,, ,,

-

normaldays = ( y I) '365 ; ,, ,,

1 -32768 to +32767

long int -2147483648 to +2147483647

KlClT I C I Lecture 3

a

a

I

What's Wrona Here'r

-

normaldays = ( y I) ' 365 ;

c? float a ;

; float a ;

-

Soln: normaldays = ( y Soln: normaldays = ( y 11 ) 365 ; 4 -Soln: long Int y :

l

The sizeoft ) O~erator

six O-A u (J

int i ; long int j ; prlntf ( "%d % d l sizeof ( I ), sizeof ( j ) ) ;

-L\w

WU~U bib

4

rwm9

w&&J

Keyword

Are You Sure? 4 % 3 - r n

,

3 % -3 % 3 % -3

u

4 4 4 -

L 4

ip: Sign of remainder Is me as slgn of numerator

2 3

4ea

int a = 5 , b = S , c = S ; i((a==t]==c) prlntf ( -Hello':)

;

KlClT I C I Lecture 3

;

e h

cOLei~ be.

.

What Will Be The O u t ~ u t

I

-F\O

rn

'U Joe

WI

-ad ? v r n rkm'b & !- p h d d J

b=30; printf ( "%dm,b ) ;

nh.

I

What Will Be The O u t ~ u t main( )

I

Tip : Truth In C is nonzero, whereas,falslty Is zero.

int a = 10 ; if ( a = 5 ) printf ( "Hi" ) ;

6 9

if(a=5)+

if(=)+

if(5)

main()

:--

Int m l , m2,m3, m4,rn5 ; lnt per ; prlntf ( "Enter marks In five subjects" ) ; scanf ( "\n%dY.d%d%d%dn, &ml, &m2, &m3, &m4, &mS ) per=(ml +m2tm3+m4+m5)15; lf(per>=60) prlntf ( "Flrst divislon" ) ;

rrse

I f ( per>= 5 0 ) prlntf ( "Second dlvlslon" ) ;

;Ise

if ( per >= 40 ) printf { "Third dlvislon" ) ; else printf { "Fall" ) :

1 )

KlClT I C I Lecture 4

sdo4em.d.

Lo&

Ak "d

main( J

I Int rnl, m2,m3, m4. m5,per ; prlntf ( "Enler marks In five mubjeets") ; scant ( "%dY.d%dY*d%d", Lml, &m2, am3. bml, h m 5 ) ; p#ra(mZ+mZ * m 3 + m 4 + m 5 ) / 5 ;

If(per*-W ) prlntf ( " F l n t dlvlslon" ) ; If ( p a r > - 5 0 ) prlntf ( "Second dtvlslon" ) ; prlnti ( "Thlrd dlvlslon" 1 :

prlntf ( "Fail" ) :

I----

Inlrnl. m2, rn3, m4, m5, per ;

prlnti ("Enter mark* In five subjects'' ) : scanf ( "*hdXd%d%dY.d, L m l , Bm2, Lm3. &m4. am5 ) ; prr=(ml tml * m 3 + m 4 * m 5 ) / 5 ; If (per >= 60 ) prlnll( "Flrwt dlvlrlon" ) ; l l ( per 50 printt ( "Second dlvlaion" ) ; If ( pat ?= 40 && per < 50 ) prlntf 1 "Thlrd dlvlrion" ) ;

*=

111m

prlntf ( "Fall" ) i

1

(

c;>

Int m i , m2,rn3, m4, m5,per ; printf ( "Enter marks in five cuh~ods" );

runt ( "Xd%d%d%d%d",&mi,&m2,am3, &ml,LmS ) ; per=(ml+mZ +m3+rn4+m5)/5; if ( per prhtf >= 60F i )r s t d~vlslon"1 ; if ( per >= 50 a& per c 60 ) printf ( "Second division" ) ; I f ( per - 4 0 L& per c 5 0 ) prlntf "Thlrd dlvlslon" ) : If ( per r 40 ) printf ( "Fall" ) ;

1

KlClT I C I Lecture 4

Is This

Loqical Operators

Useful in

j

'iP

C'

'

checking? Ranges

/

;h

I Problem

prlnn ( "Enter age. sex. marital status" ) ; scanf ( "%d%t%c", Bags, as, f ( ms = = ' m ' ) prlntt ( "Insured ) ;

L

gl...,m~,

else printf ( "Not In

if ( age r 30 1 -pint! ( "lnsured" ) ; else .. 1

printf ( "Not I n s u r e d )

1

;Ir

I

if age > 25 ) prinlf ( " l n s u r e d ) ;

Int age ;

chars, ms ; prlntf ( "Enter age, sex, marital status" scanf ( "%d%c%c", &a e, as, &ins ) if(Ims9.'m'lll(ms 11 [me= = 'u' &&

B

s = 'f

prlntf ( "Insured") ;

Q

else prlntf ( " ~ o itn s u r e d ) ;

KlClT I

)XI

C I Lecture 4

88 ape > 25 ))

QL mh o m ecltEhtw ~t b ~ b i & 11534 +3bt+k b b b e b .

Workinq of && And

False ,

i

True False 6

False False True

I

False True True

False

,

False False

hula3

0

0

0

0

1

1 I

0

0 0

U

OR

0 \

I

I

I

Arlthmellc Arithmsllc

+c

T

=.

C-1

<= >=

Relational

[=

Exchancinq Blocks rnaln( )

main( )

I inta=3, b = 4 ;

inta=3,b=4;

if ( a < = b ) printf ( "A" ) ;

if(arb) printf ( "B" ) ; else printf ( "A" ) ;

else printf ( "0" j ;

1

1 Output:

A

KlClT I C I Lecture 4

Output:

A

main( )

main( )

ff(a<=b) printf ( "A" ) ;

i f ( l a > b) printf ( "A" ) :

else

else

I

:.

net&=

p

pr~ntf( "B" ) ;

printf ( "B" ) ;

1

output:

A

output:

:.ButptCt 0 .

anta=3,b=4;

lf(lIa>b)) printf ( " A ) ; else prinif ( "B" ) ;

1 output:

A

Yet Another Way main( )

main( )

I inta=3,bE4; it(!(ac=b)) printf ( "0") ;

Inta=3, b = 4 ; if ( a > b ) printt ("B");

else

else printf ( "A"

1 Output:

1;

fl

KlClT / C I Lecture 4

printf ( "A" 1 ;

1 Output:

4

What Would be The O u t ~ u t main( )

I Int a

-

3, b

= - 4, c ,d ;

cwla; dmlb; printf ( "%d %d %d %d", c, d , a, b ) ;

main( )

I

Int a

= 3, b = 4, c :

printf ( "%d %d", b, c )

1

e m : L ~ o l U e wdJ

main( {

Int a = 3, b = 4, c ; c=!all(b=7); printf ( "%d %d", b, c ) ;

1

KlClT I C I Lecture 4

Yet Another Way

I

inta=3,b=4;

if(a<=b) prlntf ( "A" ) ; else printf ( " B ) ;

Output:

A

1

..

..

a *r b 7 prlnff ( "A" ) : pflntf ( "6" 1 ;

HOW

would

If ( a < = b ) prlntf ( "A" ) ;

I

YOU

Convert

a c= b 7 printf ( " A ) ;

+I

Remove The Error { inta=3, b = 4 ; a <= b 7 printf ( "A" ) :

1

KlClT I C I Lecture 4

-

I

a <= b 7 printf ( " A " ) : '.

1

I Terminator] 3 S0ln: a c= b 3 printf,( "A" ) : printf ( " " 1 ;

aabtgnmd

< - b ? p r i n l l [ l a ~ ) (: . = a ) ;

bnO

+ Use one, use another 4 Dummy

statement

main( ) Int a = 3, b ; ~1<~5?(b=IO):(b=20); prlntf ( "%dl1,b ) ;

1

r prlntf ( "%do',a <= 5 7 10 : 20 ) ;

KlClT I C I Lecture 4

0

fl

int a = 1 0 , b = 2 0 ; float c = 3.14, d = 6.28 ; printf "%d %d %f %f ",a, b, c, d ) ; print! ( "%d %d %f %d ", a, b, c, d ) ; printf ( " " / ~%d f %f %f ",a, b, c, d 1 ;

CIS^ 7 8 1 h D , Q O O / -i.g2?e ~

Conversions Continued ... main( ) {

int i = 65, j = 90 ; char ch = 'A', dh = 'Z'; printf ( "%d %d %c %c", i, j, ch, dh ) ;

printf ( "%c %c", i, j ) ;

printf ( "%d %d", ch, dh ) ;

1

int 1 = 65 ;

Re~resentation float a = 3.14 char ch = 'A'

7 ii I

B ~ n a r yEqv.

KlClT I

Binary Eqv.

C I Lecture 5

ASCII code

5

ASCII Codes

\

I

inary Is Difficult .-

I

I ' :

Character

Decimal

A

Of 0000D1

B

01000010

C

01000011

D

i E

I

I

I

I

I

"

01000100 01000~01 ""

68 '

6i

I

..

Methods Are Different char ch = 'A' = 65 ;

int I

pr~ntf( "%cT7.i ) ; 4 printf ( " % d U , ch ) ;

KlClT I C I Lecture 5

14

+ 65

;

I

Characters to be Kenreranted

.-

+ 26 +2

+fO + 32 + 34

I

Capital letters ( A- Z ) Srn.lh.*. 1.11.~ ( 1) cb Digits ( 0 - 9 ) Spwlai Symbol8 ( + 1 . : ; etc. ] Non-prhkblr cham control chars Graphlc charactem

-

+ 128

256 00000000 To l l t l l l l l

€9+ b b ,,kt h r n( e . ~b l e .) ,,A p m b a ehcye

What About More Than 255

Whv Unreliable Conversions float I = 3.14 ; printf ( "%em,i ) ; prlntf ( "Kd", i ) ;

i / ~ ~ a n d l s ~ ~ s m 0 nd md l lsa l~0 m a n d l a

Int I = 35 ; prinlf ( "Wf". I ) ;

i 0sandI1 I ~ s n n d t s l

KlClT I C I Lecture 5

I

1

Sur~rised?

rain' '

float a = 0.7 ; if ( a c 0.7 ) printf ( "A" ) ; else printf { "B" ) ;

1

= 04d=A .

I

Aanearances Are Misleadinq tloat a = 0.7 ; printf ( " X d K d , slzeof ( a ), stteof ( 0,7 ) ) ;

1

Binary of A Float

Truncated after 64-blt

KlClT I C I Lecture 5

I

Local vls S l U vls 1SU Calls i

printf ( "in I am In main" 1 ;

CdlD c & )

-+K q c n u I )

mdm

---3 Communication

(n-oem

main( )

(

~ l s c&) a

* ,b&

Int a = 10, b = 20, c = 30 ; Int s ; calsum ( ) ; printf ( "%dU, s ) :

>calsurn( I )

<

L

v

Passinq Values main( )

I

1

calsum ( int x, Int y, int z ) int

I

W

&w&@I iM

lnt a, b, c, r ; s=a+b+c: prlntf ( "Kd", s ) ;

(

I

s,

Arguments

prlntf ( YO^", s ) ; I

KlClT I C I Lecture 8

d o w t z & h &ky)

a

=-

~

~

Returninq Values r = calsum ( a, b, c ) ; prinv ( "%dm,r )

9

calsum ( lnt x, Int y, Int

t:

Int ss ; ss=x+y*x; return ( ss ) ;

z

)

return ( 80 ) ;

---= 3 Are These Calls OK? calsum ( a, 25, d ) ;. calsum ( ID

+ 2 , 2 5 x 3, d 1 ;

calsum ( a, calsum ( 25, 10,4 ), d ) ;

.

int ss :

u=x+y+z; return ( 8s 1 ;

1 Nested calls are legal. Call wlthln 417 expression Is legal.

Returninq More Than 1 Value main( )

Ivalue at a tlme

I

Int a = 1 0 1 b = 2 0 . c - 3 0 ; int 8 , p : 3 s, p = sumprod { a, b, c ) ; prlnn ( ll%d%dy*.r. p ) ;

1

sumprod ( Int

I

*, int y, Int x )

Int

IS,pp ; ss=x+y+z; pp'x'y'z: return I ss,PP 1

;x

KlClT I C I Lecture 8

8

sqaw&

/&clmati~r

=\me

>

1

calsum ( int x, int y. int z )

I

j 5 ( = . ~

Ye25 ~ = d , y=n5%? r = d , ) = vahQ 2-r

9c&~su~~'[~s,~~,Q)

'

main( ) {

-

One More Try

-

10, b = 20. c 30 : int s. p : I sumprod ( a, b, c ) ; p sumprod ( a, b, c ) ; prlnn ( "%d~/.d",5, p ) ;

Int a

-

1

rumptod ( lnt x, Int y, lnt z ) {

int ss,pp ;

::':':':.-

,.

return ( ss 1 ; turn ( PP ;

4

durn0-b

hrr, (~1;i); $g

c!mBPh

)

The Only Wav Out maln( )

s sumprod ( a, b. c, I ) : printf { "%d%dn, s, p ) ;

n

1

sumprod ( Int w, Int y, Int z. Int code ) {

roturn ( IS ) ; else return ( pp ) ;

time

,=

,I

hw ~r)be

&-'d m

&t&.

1

II

A Better Wav

;urnprod ( lnt a, int y, Int z, Int code) -

int IS,pp ; pp-x'y'r;

return ( pp ;

KICIT I C I Lecture 8

I

%

i

d

\

q

no.

4 -J?4

1;

calsum ( int x, int y, int r )

I

N ~ H O V O JS k m d ~ d

NSI VIS K & R ,.

q

-

calsurn ( x, y, z )

Alvl~-tm

l

Kornighan B.

I Int x, y, z ;

I ) '

I

Int y ; prlntf ( "Enter year" ) ; scanf ( "Y.d", &y ) ; romanize ( y ) ;

} romanlze ( Int yy J

int n. i ; n n yy11000: tor(I.1 ; I < = n : l + + ) prlntf ( "m" ) :

1

A More General Gall maln( )

I

Int y ; prlntf ( "Enter year" ) ; scanf ( "%d", By ) ; y = romanlse ( y, 1000, 'rn' ) ;

1

romanire ( lnt yy, lnt j , char ch) ( int n, i ;

n=yylI; lor(l=l ;Ic=n;I++) prlnlf ( "%c", ch ) return(yy%]);

1

KlClT I C I Lecture 9

:

...

y = romanlse ( y, 1000, 'm' ) ; ,-2 y = romanlse ( y, 500. 'dl ) ; _3 y = romanlse ( y, 1W. 'c' ) ,;

y=romanlro(y,50,r1w): y=mrnsnlsa(y,~~,~x~)~-

,

%03

Int n, I ; n-yytj ; for(Ia1 ;I<mn;i++) prlnff ( "xc", ch ) ;

Advanced Features of Functions 4 Returning a non-integer value

+

Call by value I Call by reference

+

Recursion

main( )

float a, b, c ;%square (float) ; a=squan(2.0); Function b = square ( 2.5 ) ; Prototype c-squam ( 1 . 5 ) : printl ( " Sf 161 W ", a, b, c, 1 :

C

2.0

2.5 \ - 5 + a * D&\aa

(bmd b

C-

d*OF r.34 2 9 s

oat square ( float x )

I

flaat y : yax-x;

bcl Jalnll~P- n

9,mn

\ ~ ! w ~ n ~ f i r

float y ; Y RSqUaro [ a ) ; prlntf ( "%1". y ) ;

float square ( float x )

What Would Be The Output mrln( ) (

Int a = 10 ; prinn ( *ma = %don " Ia ) ; a=fO; prlntl ( "\n a = % d , I1 ;

.

1 f(

-

J

{

9 d y

printf ( "Hello I" ) ;

1

Int r

10 ; printl ( k l \ ~ a = % d o . , a J'O );

f0;

prlntf ("\n am Y.d", a ) :

A \\3 Returned value is Ignored.

prlntf ( "Hello I" ) ;

KlClT I C I Lecture 9

olution main( )

I

Int a = l O ; prlntf ( 'Ina = X d " ,a ) ; f( 1 ; prlntf ( " h a = % d " , a ) ;

Advanced Features of functions

+ Returning a non-integer v a l u e d + Call by Value I Call by Reference + Recursion

prlntf ( " \n address of 1 a %d" , &I ) ; printf ("ktvalueof I = ' A d " , ' ( & I ) ) ;

KICIT I C I Lecture 9

-x

Would lhls Work ... Int I = 10 : j=&i;. j= jEg(i434);

/--

a m : ----

wad

LO&

prlntf ( "%do, 'j ) ;

variable, constant

"

lnt I 10 ; Int 'j ; Int '*k ; 4 B BOtO 9 1 2 prlntf ( " \ n v 3 l u a o f I = % d " . 1 1 : v n o~ ~ p 1..

I

. . .. .

-. * ( a t ) ;V )m$ 1

prinni l * i n v a ~ u c o f i =YO^

7n

1 1

Jmal;-tadddish&hj.

~ H n f f ( " h a d d r e a r o f I = X d " . 8 1 : .,AAL

-

.

-- ,

,

,

-r

'

I

-- , --. ,

-

-9 6 ~ 0 5119, , BY).hrnJ6o1o.

r---

vnlue

"j

"-'x.Lq

&s

a

,

4

variable

*&variable

-. J

-

"

id *k;

KlClT I C I Lecture 9 J&

c*k=v&

of 4bolo

b &clk iht L C L ~ ~;SC ~ urn9 C*k j * k ~ v ~ d h @A~ am @ 'lea.

0xB8000000 whlle ( 1 ) I s = Ox88000000 ; for ( I = O : ler1999; I + + ) {

( .(s+I)

Z=

'A'

a& *(s+I) u 'zl )

*(s+L) a *(s+i) + 32 ; else ( . 'a' && *(*+I) cif *(s+l) = *(s+g E *(s+/) 32 ;

1

1

1

-

1

KlClT I C I Lecture 9

'2' )

I-

char tar 'r ;Int r ; char far Y ; char sh ; 110x68000000 ; Int c ;

-

-

for ( c = 0 ;e <= 79 ; c++ ) ur ( ch = * ( 8 +c.2); kr(r=l;ra24;r++)

I 1

1

KICIT I C I Lecture 10

?in

(1

/

Bells And Whistles ' ~raaooooooI I Screen I

/

char far 'v ;Lnt r, c ; s = OrB800MHIO :

v l I I J +a

1

c = random ( 79 ) ;

mund I-

, .. Are Thev Same

I

char h r s ' ; char far % ;

char Gr 'a, "v ; char k r 'a

E]

char far *s,far % ; 7 -

:

for ( I = 1 ; I C* 3999 ; i += 2 *(s+l~-color;

KlClT l

C I Lecture 10

2

pr-;m

e Caps Lock Un ,

main( ) {

~oggle Kmys Capr lock. Num lock Scroll lock Inwrt

char far *kb ;

kbrOx417 ;

How would you put off

v&

'~u h et

on't Do Delete chat far 'kb : kbaOx417; prtntl { "PI. press delete key"); *kb = l 2 ;

I

-

rthdav Josh1 7 6 5 4 3 2 1

0

<--

I Our Program

L

Del-Ctrl

KlClT I C I Lecture 10

Alt + Del

['\a+

vim D&

rtD &ah&. h C M *+QJ

3

what would be the o u t ~ u t mln( 1

I

1000 2090 9000 lnti=10;flo8ta=3.~4:charch='z'; j b dh Lnt 7, "k ; float 'b, "c ; char 'dh, "ah j=&i: b-&;dh=Lch; 4000 5000 M O O k-&J;c=&b;eh-ldh; k c oh pdnH ( " % d # d % d M j , b , d h l : , c c z ~ rcc MO 1500 2500 prlntl .Ad %d'Ad", 'k ,'c , 'ah ) :

;-I

m'.

1-c.

m W [ 0 0 1 1 8 0 0 P ]

Lcm

prlnbl("%d'AdW',sltmof(I),sluof(a),rl~f(ch 2 1-1 I

1);

...

[~ontlnumd

dky+Sinm

] 4 0 0 0 1 w 1 prlnH('9hd %d%d",slxooi(J), slzoof( b ) , rlzoof(dh) ) ; pr/ntf ( "%d w

KQ-2-

w",sizeof ( k ), mhd ( c ), rlzed ( ah ) ) ;

prlnff ( '%d %f %en ,"k, -c, "oh } ;

\1292,

c main( )

I

int i * 25 ; int *j ; float a = 3.34 ;float *b ; char far "kb ; kboOx417; j-&i;

KlClT I C I Lecture 10

dteIadn)l&o &

@w +bock M ' E!&

Pointer Sizes main( ) {

float 8 3.14 ; noat *b ; char h r *kb ; kb = Ox417 ; J

b

= &I; = 8.;

Int far *m ; m = 0x413 ;

KlClT I C I Lecture t 0

fi)'

he btomvdios

I

.

C B n w i -~- O r R % c ~ @ o o

C~~XINJ&Eh a UMUS .--

?in(

1

Int a n l o , b = 2 0 ; ,o,~,o pdntf ( "KdYod", a, b ) ; /L C rwapv(a, b 1 ; 10 prinn ( "%d%dn. a, b ) ;

&& &

1 J

x

swapv ( Int x, lnt y )

I

Y

t

110]150]110]

int t ; \O t * x ; x = y ; y - t ; TO prlnti ( "%d%dW,x, y ) ;

x

Y

t

X

Y

t

pi-'pJB

1

pqwm k.s=W

Q=\O

-

int a = I O , b = 2 0 ; prlntf ( "~/ld%d",a, b ) ; 17 ' swapr ( &a, &b 1 ;

1

swapr (lnt 'x, lnt 'y ) I Int t ;

1

I

-

0

X

.

Y

t

'v = t ;

;urnprod ( Int x, Int y , Int z,int 'as, Int 'pp ) { ..rrx+v+z:l a b

KlClT I C I Lecture 10

I

P

n heLSQ be u pk. : .

char 'n[ ] = {

I "Sanjay", "Amol", "Slvaramkrishnan",

1:

Selection

I

..

int I, ] ; char 't ; for(I=0;1<=3;l++) I

1)

\

~O~(I=O;IC=~;I++) printf ( "fds", n[ i ] ) ;

yarn(

1

I

Calendar

1/8/1~9-? 1HI1 Mon

Int m, y ; lnt leapdays ; long In1 normatdays : long int totaldays ; prlntt ( "Enter month and year" ) ; scant ( "%d%d", Lrn, & y )-; -normaldays = ( y - 1 ) * 365 L ; 1--leapdays=(y-1)/4-(y-1)1100 + (y-1)1400: totaldays = normatdays + leapdays ;

1

...Calendar Int int 1, a ; inl firstday ;

..

totaldays

= normaldays t leapdays ;

-

120; for(i=O; 1
:

i / i ~999 i to 311711999

...Lalendar +,

0 'I 1c\ jYL .+- 1 rr i n t d a y s [ ] - { 3 1 . 2 8 . ~ 1 , ~ 0 ~ ~ 1 , 3 0 ~ 3 ~ , 3 0 , 3 1 ,13; 0 , 3 1

inain( )

.. ..

tolaldaya = normaldays

+ leapdays ;

i f ( ( y % d D O = = o ) 11 ( y % i a o i = O & b y % 4 = = 0 ) days[l1=29:

---7

3

1

.-

s=o: for(i=O: l < = m - 2 :I++) s = s + days[ I ] ; totaldays += s ; tirstday = tolaldavs 'b 7 :

..

1

August 1999 2 0 4 - - 2 8 i --32- & 38- 4 44.c 50-(: 56 I I I I i l l Mon--.T ue., Wed C

....Calendar

I r-rharf = 'm~nfhsi

J

I

26

20

I

l

32

l

/ "January'. "February,, , , 1 :

totaldays += s : firstday = totaldays % 7 : col = 20 + flrslday ' 6 ; clrscr( 1 ;

I

-

- --

-

- I, y ):

rintt ( "96s %d", months[ m 1 I D , 20 ) ;

gotorc

...

printl ( "Mon Tue Wed Thu Fri Sal Sun" ) ;

KICIT I C I Lecture I7

4

...Calendar

,-

I

10

;lain(

26

20

- Mon

32

I

I

...

Iue Wed

)

Int days[ 1 = ( 31, 28, 31. 30,31. 30, 31, 31. 30,

..j

;

I' print month year ' I I' prjnt days 'I rwr-12: for I = 1

: I <=days[ m - 1 ] : I++ )

golorc ( row, c o l ) : printf ( "Tbd". I ) col = col +- -6- : 11 ( col z 56 ) {

:

-

3

row++ ; cob = 20 :

1 1

c--.n u ) c-l'.tien':~! (i& ~ ~ h y ~e y~

F i11): I

I

idanf "%d%dH,am, & y

COY

...calendar]

) ;

d -

while ( 1 ) I

normaldays = ( y

-1

) ' 365L

:

Glendar

Next year

~ O I C ( 20,35

:

printi ( "Rt-Next mth ..." ) ; ch = getkey() ; switch ( ch )

'

h Kt%"C .

1 % -

t

*

Prev. year

case 77 : m++ ;

.

.

'\( -t+

-

1

1

...Calendar ) I

intdays[]= {31,28,31,30,31,30, 31,31,30,31,30,31 ) : scanf ( "%d%dn, &m, &y ) : whlle ( 1 )

i

normaldays = leapdays = totaldays = ~ f ( y % 4 0 0 = = 0 ) l l ( y % l O O ! = O && y % d = = O ) ) days[ 1 ] = 29 :

else

days[ 1 ] = 28 ;

.. -

-I.-_

1

KICIT I C I Lecture 17

K

,,

n.&

,

Terminology

iame

1 1

e:2

Salary

1

4000.50

Handlrna - Data mein( ) I char n [ ] = {'A', 'X', 'Y', 10') ; int a[ ] = { 23, 27, 28 ) ; float s[ 1 = { 4000.50, 5000.00, 6000.75 ) ; int i ; for( i = O ; i ~ = 2 ; I + + ) printf ( "Xc%d %f", n[ i 1, a[ i 1, s[ I ] ) ;

1

1;

float s ;

struct employee e l = { 'A', 23,4000.50 } ; struct employee e2 = { 'X', 27, 5000.00 ) ; struct empioyee e3 = { 'Y', 28,6000.75 ) ; prlnti ( "%c %d %f", el .n, e l a, e l s ) ; printl ( "%c %d %fW, e2.n, e2.a, e2.s ) ; printf ( "%c %d %f", e3.n, e3.a, e3.s ) ;

w \ ~he

}

n h v d d~timkp KlClT / C I Lecture 18

~+bt;l I jot&

,

& \co*e&

I+'*

Arrav of Structures struct employee I

1;

char n ; int a ; float s ;

struct employee e[ 1s {

rf

( 'A', 23,4000.50 { 'X', 27, 5000.00 ) , { 'Y', 28,6000.75 )

int i ;

I }

for( i = O ; i < = 2 ; i++) printf ( "%c %d %f", e[ i ].n,e[ i ].a, e[ i J.s)

Terminology Structure namettag char n ; int a ;

I

A structure is a collection of dissimilar elements. ructure elements are always stored In memory locations.

1 1

struct employee e[ 3 j = {

1 1 1

1

.. }

;

A 23 400.50 X 27 500.00 Y ] 28 ] 600.75 401 403 qo? 408 41 5

KlClT I C I Lecture 18

1

Arrav of Structures -struct employee e l I = ( ... 1 ; char 'p ; struct employee 'q : struct employee ('r 113)

c . - to~ ?~ array of structures

1

I

Ptr.

'

-7 I 3~ +b c k

struct employes @[ 3 I = I

1

1

.. ) :

-1

!A 123 400.50 X 27 500.00 --401

P'.

tr. to structure

* A&S ; ~

408

415

p=e ; q = e : r=e ; p++ : q t t : I++:

printf ( "YOU", printl ( "Xu",

p); q);

wz

Declarations & Definitions gtruct e r n p l o y e m

float s ;

I

iiruct employee e = { "Rahul", 25,4000.50 1 ;

char n[20] ; in! a ; float

s;

) e = { "Rahul", 25,4000.50

I I

1, x, y

'

;

Copying 1

main( ) I

I

struct ernp 1

char n[20]; int a : float s ;

e2.s = el .s ;

G i v i n g at

e3 = el ;-I-* printl ( "%s %d %1", e3.11, e3.a, e3.s ) ;

u

KlClT / C / Lecture 18

I

'd

p b

b

(93 3 Jh.Jffu@.

QOoJ3

Copyinq Arravs

int a1101 = { 3, 6, 5,... 1 ; int bIl 0] ; f o r ( i = O ; i < = 9 ; l++) b[i]=a[i];

struct z {

1;

int srr(lo] ;

struct z a = { 3, 6,5, .., ) ; struct z b ; b=a;

truct address

; int

I

age ;

i i u c t emp e=( "Rahul", 23, "Ngp", 44010,4000.50

}d

Passina Structure Elements main( ) { struct book

{ 1:

char n[20] ; int nop ; float pr ;

ktruct book b = { "Basic", 425, 135.00 ) ;

1

dlspla ( b.n, b.nop, b.pr ) ; show rb.n, &b.nop, bb.pr ) ;

display (chbr *n, int pg, float p )

' 1

printf ( "%s %d %I", n, pg, p ) ;

;how ( char *n, in1 *pg, float 'p ) I

1

printf

"%s %d %f", n, 'pg, 'p ) ;

KICIT I C I Lecture 18

ho\d

P a s s ~ n gStructures struct book char n[20] ; Int nop ; tloat p r : siruet book b = ( "Baalc", 425, 135.00 ) ;

1

displayl ( b ) : showl ( &b>~-----------) /--

display1 ( struct b 6 k bb ).

I

-

printf ( "%s %d %I3', bb.n, bb.nop, bD.pr ) ;

/rr to

showl ( struct book 'bb)

I

I

printf ( "'As %d %f", (' bb ).n, (' bb ).nap,(' bb ).pr ) printf ( "%s %d %f", bb -> n, bb -> nop, bb -r pr )

Complex Nos. --U rstruct corn

I

[ I

+

OA ~hf--hm+ 9

struct corn a = ( 2.5, i.3 } ; struct corn b = I1.2, 1.7 ) ;

I

struct corn c ; struct corn add (struct corn, struct corn) ;

: 7-7 struct corn z ; y:r ; *xf y.1 ; return z ;

2 r

(mainO

+

a en\Lng

+

Complex Nos.

float a [ ] = ( 2 . 5 , 1.3); float b [ ] = ( 1 . 2 , 1 . 7 ) ; float *c , float ' add ( float *, float * ) ; c=add(a, b ) ; printf ( "%f %f", ' c , ' ( c + 1 ) ) ;

b=&.

I

I

'

-

ons of Structures + Pooltlonlng Cursors + Recelulng aecll and scan codas + Dlsplaying characters Prlntlng on prlnter 4

Mause Programmlng

4

Graphlcs Programmlng All Disk Operstlons etc.

4

Endlsk

II * Faster

KICIT I C I Lecture 18

Iplatter ( aluminium ) )

Parts of platter

of same capacity

KlCIT / C / Lecture 18

07)hi-

%a~

9 air q i a a\(

i+.

Readina Boot Sector #~nclude"dos.h"

Fain{ char arr [ 512 ] ; lnt I ;

1

printf ( "Enter floppy in drive A press any key ..." ) ; getch( ; ebsread ( O , l , 0.arr ) , for( 1 = 0 ; 1 < 5 1 2 ; I++) printi ( "%cV, err 1 I 1 1 ;

KlClT / C 1 Lecture 19

-

& B I J ~&\eb J ~ & s P . F,hcr P c ~ i ar n f L i s ~ , b& 5 %S i+ w t o Oie* &fi0di* ,

~b~wad=

~

d & k. p I k ~ & ~ a]89.

GVctb

@

Boot Parameters No-

Kb

1.2 Ub

1.44 Mb

2

512

512

512

2

1

1

1

720

2400 2880

2

7

9

9 2 0

35 2 0

18 2 0

360

,,gs

Descrlptlon

Jump lnstructlon System 10 NO. of byteslsector No, of seetorslcluster No. of sectors In reserved area No, of copies of FAT . Max. no. of root dlr. entries Total no. o l sectors Medla descriptor No. of sectorslFAT No. of sectorsltrack No, of sides No. of hidden sectors

2

2 2

&ch

h b cm h a (3+ChA0,mam

w a 3 d ~ w h pwacedy n we- w ~ W n qdCf mtaei, ih B struct boot ..

I i

-Im a r lump1 . .*.1 ;

I Descrlptlon

3

IT3

Jump lnstructlon

w

...~ o n( t

include "dos.h" yain( )

I

I

struct boot char jump[ 3 ] ; char sysld[ 8 ] ; int bps ; char spc :

..

',

:

struct boot b ; lnt I ; absread ( 0, 1,0, &b ) ; lor(l=0;Is=2:1++) prlnti ( " % X , b,jurnp[ I ] ) for(1=D;I
-

I

b'

ol8 did it

:

dl&&

8)-&4 f

m

d

p

+ Ach

&@no.

H ~ o cw.

In General absread ( drive no., no. of sectors to read, sector from where reading should beg~n,butrer ) ; absread ( 0,1,0, &b ) ;

sector relorred uuinn

LW-

& no.

Typlcal Obtains Values Values t02

€83190 lBM3.3

Bytedsector 08s Secforslclusler Sectors In reserved area

Maw. root dlr. entries Total no. of sactars Madta descrlator

512 1

.... 20480 0

I

I -24

2 224

1 '": 1 1 0

O

SO

4

dl- boot & WuNb

Sides

-9

nldaen *actors

w

i~L

J C A

so b.~& cl~wmw b@w2a--

Anti-Viral

# Include "dos.h"

main( ) l printf ("insert infected disk, Press any key" )

getchl)

:

-

--

1

fl

l o +"d

Q

.

M-Cm4*

eo08*&kab.

20 880

KIClT 1 C 1 Lecture 19

3

#include "d0s.h"

Better...

char a[ 512 ] : char ch = 'y' ; char 'names[ ] P ("0Jerulalwrn'+, "Yankee Doodle",

"Robinson Cruso", "Eddle Murphy", prlntl( "lnaert unlniectmd dlak, Pteas any key" ] ; getch( ; absread( 0 , 1 , 0, a ) ; whlle ( ch = 'y' ) prlntf ( "Insert Infected dlsk, Press any key" )

... 1 ;

r\

:

abswrlte ( 0,1, 0, a ) ; prlntf ( "Another dlsk yln" ) ; ch = getche( ) :

&

disp\% =kG_~l\l~ ih hamQ

4 bytes

Il Include "do8.h"

yaln(

1

rruct

1:

Printincl Directory

entry char n[ 8 ] ; char ext[ char unused[ 17 ] ; long Int size ;

struct entry e [ 16 ] ; Int I, : prlnll ( "Insert dlsk, Press any key" ) absread ( 0 , I , 19, e ) ; for(i=O:i<=l5;l++)

: getch( ) ;

tor(j=O;j<=7;j++) prlntf ( "%c", e[ 1 ].n[ j 1 ) ; lor(j=O;j<=2;j++) printt ( "%c0, e[ I ].ext[ j ] ) : printf ( "Xld", e[ i ].size ) ;

y'iq %C

CIT C / Lecture 19

natdfr &WQ

&

OP

Related Documents