Monday, July 20, 2009

First LE

Exam Coverage
  • From the beginning to for loop.

Exam Type
  • Identification
  • Writing C statements
  • Programming (Flowchart + C Coding)
  • Debugging
Hi Guys and Gals! Dagdag ko lang itong slide na hindi ko pa na upload. Good luck!

Data Into Information

Sunday, July 12, 2009

Source Code Editors for Windows

If you have managed to install MinGW using the instructions on my last post, you must be wondering what text editor you may use. In its purest sense, you can use any text editor like notepad. Just save your source files with the .c file extension.

But the thing is, notepad lacks that token coloring scheme and line numbering we see when we use gedit in linux (ubuntu). Fortunately, there are a number of free and open source text editors around. The following are just two:
  1. Crimson Editor is a freeware source code editor for Windows. Click here to visist its official site.
  2. Notepad++ is also a relatively well-known source code editor. Unlike the latter, Notepad++ is not only free but is also open-source. Meaning, people may download and edit its source code legally. Click here for its offical site.

Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it.

- Brian Kernighan

C Compilers for Windows

MinGW or Minimalist GNU for Windows
This is the gcc port to Windows we use in class.
  1. Click here to download MinGW-5.1.4.exe
  2. Run the program.
  3. Download and Install.
  4. Don't change anything.
  5. The default installation directory, as pre-configured within the installer, is C:\MinGW. Unless you are very sure you know what you are doing, you should not change this; in particular: never install MinGW into any directory which includes spaces in its absolute path name. - from the official guide
  6. Change the Environment Settings using the instructions below excerpted from the official guide
  7. Run command prompt by going to Start->Run.. and typing cmd then enter (in Vista, you can immediately type cmd in the Start Search area). Locate your source code by jumping through files using the cd or change directory command like what we do in class. Type cd .. if you want to go back to the parent folder relative to your current location.
  8. Use dir instead of ls to list the files and directories in your current location (or directory)
  9. Make sure that your source code is inside your current directory.
  10. Compile your source code, for example hello.c by entering the command gcc hello.c -o hello
  11. You will notice that a new file hello.exe is created. Note that by default, if you do not type any file extension, the executable file will end in .exe. Though you can explicitly specify the file extension.
  12. Execute your compiled program by inputting the command hello.exe or just hello (for .exe files only). No need to prefix ./
Environment Settings

When you install command line tools, such as MinGW, or GnuWin32 tools, you have to tell the command line interpreter where to find them; this is usually accomplished by adding the appropriate directory names to the PATH variable in your environment. Typically, it is your responsibility to do this; please do not expect the installer, (if you used one), to do it for you.

Warning: Adding entries to the PATH is normally benign. However, if you delete, you may mess up your PATH string, and you could seriously compromise the functioning of your computer. Please be careful.

  1. Right-click on "My Computer" and select "Properties".
  2. Click Advanced -> Environment Variables.
  3. In the box entitled "System Variables" scroll down to the line that says "PATH" and double-click the entry.
  4. You will be presented with a dialog box with two text boxes, the bottom text box allows you to edit the PATH variable. It is very important that you do not delete the existing values in the PATH string, this will cause all sorts of problems for you!
  5. Scroll to the end of the string and at the end add ";\bin". Here is the full absolute path name of the installation directory; if you accepted the defaults when installing tar and gzip, then for these, it will (probably) be C:\Program Files\GnuWin32, while for MinGW it will be C:\MinGW\bin, (if you kept to the recommended default installation directory). Don't forget the semicolon; this separates the entries in the PATH.
  6. press OK -> OK -> OK and you are done.

Turbo C
  • You can check here for a relatively detailed instruction on how to install Turbo C. I think you need a floppy disk but a flash disk might work as well. Anyways, I am not a fan of Borland and I did not even try to install this on my system.


Dev-C++ and wxDev-C++
The latter is a somehow newer version of the former. Both are IDEs or Integrated Development Environments bundled with MinGW. Basically, Editor+Compiler in one package.
  • Click here to download the 'latest' version of Dev-C++ or here for the official site.
  • Click here to download the latest stable version of wxDev-C++ or here for the official site.


Be ready for your first programming project.

Tuesday, July 7, 2009

Notes 2

Errata:
Slide 35 - "scanf() – general-purpose output routine."

05 ES26 Lab - Data Types