cs16wk05c

cs16wk05c - for for More natural than while to implement...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
for for z More natural than while to implement counter-controlled loops : int c; for (c = 0; c < 10; c++) /* statement ; or {…} */ –e .g . , Program chapter3_3 (p. 106) z Note: header requires three fields (i.e., always two “ ; ”), but okay to leave blank or even use , to do multiple things ini ti a l i z e c m a i r e
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
do/while do/while do { ... /* loop body */ } while ( boolean expression ); –e .g . , Program chapter3_2 (p. 104) z Notes: – Always executes at least once
Background image of page 2
break break , , continue continue statements statements z Sanctioned ways to loosen the structures – Without using the dreaded goto statement! – Usually as a result of some condition: z e.g., if ( /* a good reason */ ) break; z break – says exit the structure now – Control diverts to 1 st statement after closing ` } ` z Already saw how it skips remaining cases in switch structure z continue – says terminate this iteration of loop – Repetition structures only – restarts at next iteration
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
File input File input - - output in C output in C z First note these equivalent function calls: scanf( ) ÅÆ fscanf ( stdin , ) printf( ) ÅÆ fprintf( stdout , ) getchar() ÅÆ getc( stdin ) putchar( ) ÅÆ putc( , stdout ) z Q. What are stdin and stdout ? –A . File pointers (type is FILE * ) – they “point” to standard input and standard output z Of course you can point to a disk file too! fopen ( )
Background image of page 4
Opening and closing files Opening and closing files z Actually means associating and disassociating file pointers with the files z e.g., FILE *fp = fopen("mydata", "r"); "r"
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/01/2011 for the course CMPSC 16 taught by Professor Costanzo during the Spring '11 term at UCSB.

Page1 / 17

cs16wk05c - for for More natural than while to implement...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online