Here are some more useful Unix tips. If you want to repeat a command that you did earlier, you can use C-p or the uparrow key to retrieve the previous command. You can repeat these to go further back in your command history. If you go too far, you can use C-n or the down arrow key to go forward in the command history.
If the command that you retrieve is not exactly what you want, you can edit it before hitting carriage return. Many of the basic Emacs editing commands can be used, such as C-b (back one character), C-f (forward one character), C-a (beginning of line), and C-e (end of line).
If you run a C program and it crashes, it leaves behind a core file. A core file is useful if you wrote the program that crashed and you want to debug the program in a debugger. Otherwise, core files are very big and very useless. If you get a segmentation fault or a bus error, there will probably be a core file laying around. The core file is named with the name of your executable file appended with .core. So, if your program named charcount crashes it will leave behind a file called charcount.core.
When you edit C files in Emacs, Emacs automatically enters C mode. It knows that you are editing a C file when you visit a file with .c for its suffix. As a result, if you create a buffer and start typing a C program, it won't go into C mode until you save the buffer to a file with a .c suffix. C mode provides you with help in formatting your C programs. For example, if you use C-j to end a line instead of the return key, Emacs will create a new line and indent it to the appropriate level. When you type a }, it will find the matching { and briefly highlight it for you. This will help you make sure that your brackets are balanced.
You will also notice that Emacs uses colors to help you tell at a glance what different pieces of the program are. Comments will appear in one color, keywords in another, identifiers in a third etc. Having different colors for comments and for code is very helpful because it will help you find situations where you have accidentally commented out code or failed to close a comment. Other than that, well, it looks cool.
There are also two additional "minor modes" that you can turn on and off as you prefer. (By default they are off.) The first is auto-newline insertion mode. When this is on, Emacs will automatically insert newlines when you type certain characters, like {. It's pretty handy. The second mode is hungry-delete. When this mode is on, the backspace character will delete all the consecutive whitespace characters preceding the cursor, not just the immediately preceding one.
Here are some useful commands:
C-j
Insert a newline and indent the next line.
C-c C-q
Fix indentation of current function
C-c C-a
Toggle the auto-newline-insertion mode. (If it was off, it will now be on and vice versa.)
C-c C-d
Toggle the hungry delete mode
Also note that there is an Emacs info page about C mode so you can learn more.
Initially, set all the elements of the array to TRUE. On completion of the algorithm, if an array's value is TRUE, it indicates that the array's index is a prime number. For this algorithm, the 0th entry of the array is essentially not used. For example, when you are done the 1st, 2nd, 3rd, 5th, and 7th entries should be true since 1, 2, 3, 5, and 7 are all prime numbers. 4, 6, 8, and 9 are not prime numbers and so the values indexed by those numbers should be FALSE.
Begin with the number 2. Since 2 is a prime number, leave the array indexed by 2 to be false. Every multiple of 2 is not prime, so go through the array and set every entry indexed by a multiple of 2 (greater than 2) to FALSE.
When you're done with 2, repeat the process using multiples of 3.
When you get to 4, you should check and discover the array value indexed by 4 is already FALSE. Thus, 4 is not prime and all multiples of 4 will also already be marked as not prime.
Continue until you have eliminated all non-prime numbers. Think about what the last value is you need to check. If you want to use standard math functions, include the file math.h, just like stdlib.h, etc. The function names are sin, cos, exp, log, pow, sqrt, and so on. They all take doubles arguments. As in most languages, passing an integer value to these functions implicitely "promotes" the value to a double. To compile a program using these functions, provide "-lm" as another command line argument to gcc.
When done, make one more pass through the array, printing out all the prime numbers you have found.