|
|||
|
Se far we've only used the output portion of the standard input/ouput library, stdio.h. In the SCANF directory of the week1 folder you decompressed from week1.tar, we see the input function from that library; namely, scanf. Scanf works almost exactly like printf; it takes a string as the first argument, but the string only contains the format identifier; it must match the data type of the variable we'll use to store the value input by the user. The variable that we're using is the next argument to scanf, with an addition; we place an ampersand & in front of that variable, so that the value input by the user goes into the right place (We'll discuss the ampersand at length when we get to the pointers module). Compile and run sumi.c and productf.c from the SCANF directory, inputting the values of your choice when requested, and note the results. Now, let's think a little bit about what would happen if we violate one of the rigorous syntax rules that govern the construction of C programs.
If we violate syntax rules, we get an error during compilation, and it won't generate an executable file. However, if the syntax is correct, but we mess up on the grammar (Like a data type/format identifier mismatch), the program will compile, but something will go wrong during program execution. These kind of bugs are subtle in nature, and often much more difficult to detect. Keep this in mind when you write programs; specifically, read and reread your program, going over it line by line, making no assumptions, and you'll likely save yourself significant time with reduced debugging. To help commit the important concepts we covered in this module, take a look at the tutorials we mentioned in the previous Basic Concepts Module.
And if you notice a discrepancy between one of those tutorials and our modules, or if you find a method of instruction you find particularly compelling, please do not hesitate to bring it up to Dr. Impelluso or Joshua Bleier, the designers of these modules. We're always looking for ways to improve this course, and your input is an importnat part of making that happen. |
||
Website by Joshua Bleier |