Programming Practice


The purpose of these practices is to, well, practice your programming skills. Some of them are very easy, and others can be a little challenging. These are highly recommended as an additional way to improve your programming skills.

IMPORTANT:
  1. DO NOT USE INTERNET EXPLORER. It will just cause you endless headaches.
  2. When downloading files, DO NOT save the web page, save the file. To save the file with Firefox, right-click on the link and choose "Save Link As..." This is so that all of the formatting in the file is preserved.
  3. Don't forget that you may need to use the --strip-trailing-cr switch with diff if it's telling you that all of the lines are different.
  4. In order to help automate the testing of your code, you will want to use input/output redirection. If you understand this simple concept, it will help you automate your own testing.

    Normally, output (e.g. printf) sends its output to the screen. To send it to a file instead, use the greater-than (>) symbol:

    myprogram > out.txt
    
    Any output from myprogram will go to a file named out.txt and you will see nothing on the screen.

    Normally, input (e.g. scanf) is read from the keyboard. To have the program read input from a file instead, use the less-than (<) symbol:

    myprogram < in.txt
    
    All input to myprogram is read from in.txt, and the keyboard is ignored. Also, none of the characters that are in the file will show on the screen.

    You can redirect both input and output at the same time like this:

    myprogram < in.txt > out.txt
    
  5. The dumpit program. Dumps files in hexadecimal. Here's a binary version for Linux. Here is a binary version for Mac OS X. On Windows, you should put this in your PATH somewhere. These tools are helpful when testing some of your programs.

  6. There are 12 additional practices here. Many of these are simpler than the ones on this page. So, if you're having a little difficulty with the practices on this page, try the simpler ones first.


NameMain topics
1. squares1 Looping
2. squares2 Looping
3. squares3 Looping
4. numdigits Looping, operators
5. sumdigits Looping, operators
6. dice1 Looping, random numbers
7. num2words Conditionals using if and/or switch
8. scrabble1 Conditionals using switch
9. bsort Looping, arrays, sorting
10. anagram Looping, arrays
11. reversewords Strings, looping, pointers
12. slots1 Looping, conditionals, random numbers
13. coins Nested loops, conditionals
14. fileconv File I/O, looping, conditionals
15. commatize Strings, pointers, looping
16. inttostr Arrays, looping
17. strtoint Strings, looping
18. wordlen Strings, pointers, looping
19. encoder File I/O
20. fractions Structures
21. replacestr File I/O, pointers, strings
22. proper File I/O, pointers, strings
23. stripcom File I/O, pointers, strings
24. randwalk 2D arrays, random numbers
25. magic 2D arrays