Lecture 9

A little bit from everything, and loops and arrays again.

Today we visited three very similar problems. Dealing with 2d arrays,  getting command line parameters into a 2d array, and performing other operations in a 2d array. We learned an important concept, and that is command line parameters. Instead of giving your code inputs like in a dialog, where the program asks and gets inputs, you can hand parameters over to your program by simply writing them after the program call. You just need to separate them by blanks. Unfortunately these arguments are of type char * which means we have to convert them to other types in case they represent values. Converting an argument to an int requires atoi() and an argument to a float requires atof(). Check out our examples here:lecture 9 and the code for the tictactoe.c program is here:tictactoe . Next time I will go into dynamic memory allocations and pointers, which means I assume from now on that you are familiar with arrays and how to use loops.

Cheers Arend

This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Lecture 9

  1. cerebralFog says:

    // ./a.out 2 4 8 3 9 5 7 1 6 5 7 1 6 2 8 3 4 9 9 3 6 7 4 1 5 8 2 6 8 2 5 3 9 1 7 4 3 5 9 1 7 4 6 2 8 7 1 4 8 6 2 9 5 3 8 6 3 4 1 7 2 9 5 1 9 5 2 8 6 4 3 7 4 2 7 9 5 3 8 6 1

Leave a Reply