We took care in 'pgm3' to not reveal a BUG! Now's the time to point this out, and in the bargain, to look at logical testing, branching, conditional program flow.
- Open a terminal window and navigate to your desired work subdirectory.
- Open a text editor; Copy then paste the boxes below into your editor.
- Save the first block of code below as 'goc'. Save the second as 'main.c'.
- In the terminal window, make shell script 'goc' executable: "chmod +x goc"
- Invoke the compile script with the line: "./goc main.c pgm4"
- Invoke the newly-created program with "./pgm4 123"
- Test different command-line parameters: "./pgm4 apple", './pgm4', './pgm4 219'
|NOTE: Our 'goc' compiling script has changed. We can specify
the source-code filename as well as name for executable.
In this article we've got our first look at logical tests '!=' (is not equal?) and '==' (is equal?). Those new to the 'C' language will naturally think when testing for equal, the '=' is used. The statement "if (num 1 = num2)" actually tries to assign the value of 'num2' to 'num1'; the compiler will throw a warning on this. The correct syntax: "if (num1 == num2)" is correct.