Operating Systems: C Programming in the UNIX Command Line Practice Problems

Follow the steps below to practice compiling, running and solving C memory problems in the UNIX command line.
  1. Download the ZIP archive using one of the commands below
  2. Extract the ZIP archive using command unzip c-test-practice.zip
  3. Go in the directory extracted from the archive using command cd c-test-practice
  4. Solve hello-remember.c
    1. Compile using gcc -Wall -g -o hello-remember hello-remember.c
    2. Edit the source code and recompile until you fix all compilation errors and warnings
    3. Run the program using command valgrind ./hello-remember < names.txt
    4. Edit the source code, recompile and run, until valgrind reports that no leaks are possible and the program output is
      Hello Joe
      Hello Ann
      Hello John
      Hello Mary
      Hello Mike
      Hello Pam
      Still around Joe, eh?
      Still around Pam, eh?
      Still around Mike, eh?
  5. Solve matrix-from-text.c
    1. Compile using gcc -Wall -g -o matrix-from-text matrix-from-text.c
    2. Edit the source code and recompile until you fix all compilation errors and warnings
    3. Run the program using command valgrind ./matrix-from-text matrix.txt
    4. Edit the source code, recompile and run, until valgrind reports that no leaks are possible and the program output is
       1  2  3
       4  5  6
       7  8  9
      10 11 12
      13 14 15
      16 17 18
      19 20 21
  6. Solve matrix-to-binary.c
    1. Compile using gcc -Wall -g -o matrix-to-binary matrix-to-binary.c
    2. Edit the source code and recompile until you fix all compilation errors and warnings
    3. Run the program using command valgrind ./matrix-to-binary matrix.txt matrix.bin
    4. Edit the source code, recompile and run, until valgrind reports that no leaks are possible
    5. Check the content of file matrix.bin using command xxd matrix.bin and repeat the steps above until the output of the command is as below.
    6. 0000000: 0700 0000 0300 0000 0100 0000 0200 0000  ................
      0000010: 0300 0000 0400 0000 0500 0000 0600 0000  ................
      0000020: 0700 0000 0800 0000 0900 0000 0a00 0000  ................
      0000030: 0b00 0000 0c00 0000 0d00 0000 0e00 0000  ................
      0000040: 0f00 0000 1000 0000 1100 0000 1200 0000  ................
      0000050: 1300 0000 1400 0000 1500 0000            ............
  7. Solve matrix-from-binary.c
    1. Compile using gcc -Wall -g -o matrix-from-text matrix-from-binary.c
    2. Edit the source code and recompile until you fix all compilation errors and warnings
    3. Run the program using command valgrind ./matrix-from-binary matrix.bin
    4. Edit the source code, recompile and run, until valgrind reports that no leaks are possible and the program output is
       1  2  3
       4  5  6
       7  8  9
      10 11 12
      13 14 15
      16 17 18
      19 20 21