lec6-c - ECE 175 Program Design How to analyze your problem...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: ECE 175 Program Design How to analyze your problem to elementary tasks How to write pseudocode How to declare, access and write arrays Declare Initialize Access via a for loop Use array elements as variables 05/07/09 ECE 175, Fall 2007 2 Clarify use of scanf with char types Pass arrays as function arguments Return many values form a function using arrays Declare, initialize and access multidimensional arrays 05/07/09 ECE 175, Fall 2007 3 A simple keyboard input example 05/07/09 ECE 175, Fall 2007 4 scanf(%d, x); The user enters: 345\n scanf reads 345\n stores 345 to x and then pushes \n back to the input stream scanf(%c, ch_1); The first character on the input stream is the \n that got pushed by the previous scanf, so ch_1 gets the value of \n The next prompt shows up and the user inputs: g\n scanf(%c, ch_2); scanf stores g to ch_2 and \n is pushed back to the input stream 05/07/09 ECE 175, Fall 2007 5 fflush(stdin) erases the input stream buffer 05/07/09 ECE 175, Fall 2007 6 fflush does not work correctly in some Operating Systems 05/07/09 ECE 175, Fall 2007 7 05/07/09 ECE 175, Fall 2007 8 Write a program that counts the number of spaces, number of each digit and number of other characters encountered in a file 05/07/09 ECE 175, Fall 2007 9 05/07/09 ECE 175, Fall 2007 10 11 Allows identical variables to be grouped into a composite data structure Example: Scores of students in this class Declaring and referencing arrays Declaration specifies array name and the number of elements in the array The number of elements must be a constant (may use constants through #define ) The elements are numbered from 0, 1, 2, ..., N-1 Every element of the array may be viewed as an independent variable C does not check for array boundaries; so be careful in accessing arrays 10 x[0] 5 x[1] 2 x[2]-3 x[3] 25 x[4] 1001 x[5]-1 x[6] 23 x[7] Syntax: array type name[# of elements]; Examples: int scores[30]; double temp[10]; char initial[20]; 12...
View Full Document

Page1 / 38

lec6-c - ECE 175 Program Design How to analyze your problem...

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

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