Topics for today CISC105, 09/26/05 P. Conrad, Sections 022-025 Announcements: Review the course calendar... I moved the date of Exam 1 to 10/10/05 (Monday). Questions I want to consider... (1) What happens if you misspell the name of a function? What kind of error do you get? (2) How can we read _lots of data_ into a program (more than we might want to type all at once?) What are your questions? (1) formatting of numbers Q: If I have a variable that represents a number that will always be in the range 13.00 to 35.00, what format specifier (percent-thingy) should I use to print it? A: The numbers in that range take up 5 characters, and have 2 after the decimal point. (We we say "take up 5 chars", we include the decimal point as one of the characters) ++-- 2 after the decimal point || vv so 35.00 <-5-> 5 characters in all So the format specifier we want is: for float: printf("The value is: %5.2f\n",ourVariable); for double:printf("The value is: %5.2lf\n",ourVariable); Now: the exam question is: Print x=1234.56; 4 digits before, 2 after the decimal point double x = 1234.56; printf("x=____\n",x); Fill in the blank: ______ Answer: %7.2lf Suppose I want an integer, and I want it take up 5 spaces. The value is: 8 The value is: 68 The value is: 12345 So, I want to print some integer values, but I want to be sure that they all line up. The space for the values will be 5 characters wide, and the value will be "right justified" I also want one blank in front: int x; printf("The value is:______",x); What goes in the blank? %5d with a space in front, like this: printf("The value is: %5d",x); (2) Formatting dollar amounts Question: Goal 10 on project 1 says that you should know how to: print a float or double as a dollar amount, appropriately formatted. double priceOfJeep = 35000.99; printf("The Jeep costs: $%8.2lf\n",priceOfJeep); float priceOfJeep = 35000.99; printf("The Jeep costs: $%8.2f\n",priceOfJeep); (1) What happens if you misspell the name of a function? What kind of error do you get? What do we mean by a function? void printStars(void) { printf("***************************************\n"); } int main(void) { printStars(); printf("* WELCOME TO MY PROGRAM!!! *\n"); printStars(); printf("\n\n\n"); printStars(); printf("* I hope you enjoyed it!!! *\n"); printStars(); return 0; } If we change the name of the function calls to printDecorativeLine, but don't change the function definition, we get an error like this: > make printStarExample cc -o printStarExample printStarExample.c "printStarExample.c", line 14: warning: implicit function declaration: printDecorativeLine Undefined first referenced symbol in file printDecorativeLine printStarExample.o ld: fatal: Symbol referencing errors. No output written to printStarExample *** Error code 1 make: Fatal error: Command failed for target `printStarExample' > To understand this error, we need to understand the four phases of the compiler: (1) preprocessor (2) parsing (3) code generation (writing the .o files) (4) linking We will pick up there next time (Wednesday)