| Main, Syllabus, Office hours | Schedule | Slides | Daily | Homework | Code | Exams |
The majority of references posted on this page were recommended by students. Thank you for your contributions! I learnt a so much from you! - Alexandra

Requirements for system, code, programming style and programming skills.

Coding requirements

  1. We will use Valgrind to check for memory errors. (more info below)
  2. The majority of the assignments will require pointers, dynamic memory allocation and freeing the memory.

  3. Global, external or static variables ARE NOT ALLOWED in any program or pseudo-code in this class. If any such variable is used in a homework, exam, or quiz, 50-100% of the points will be lost.

  4. Know how to trace the execution of C programs.
  5. Read data from files (assuming a specific format).
  6. Write data to files in a specific format.
  7. Read data using input redirection (see example code in the Code section above).
  8. Be able to pick-up or adapt to certain ways of writing code (e.g. using functions, getting command line arguments).
  9. (Some assignments may be graded by matching your program output with an expected output using the 'diff' command. In this case your output must perfectly match the given output. Any homework that will be graded this will clearly specify that.)

System requirements: omega/VM/Ubuntu, Valgrind, debugger

  1. omega, VM, Ubuntu, or native Unix - Your code must compile and run on one of these systems. If not, you will get a 0 for that assignment.
  2. Valgrind - Your code will be run using the Valgrind tool for detecting more errors. Valgrind should not report any errors for it. Valgrind is already installed on both omega and the VM.
  3. debugger - any student must be able to use a debugger and actually use one to debug their code.
  4. optional:
  1. Compiling C code: omega/VM/Ubuntu, Valgrind
    1. omega server:
    2. VM Information - download and tutorials for installing and using the Virtual Machine (VM) used in CSE1320 and CSE1325.(This information is provided and maintained by Miss Donna French)
    3. Minimal Valgrind Tutorial - explains using Valgrind and sample Valgrind report for good and bad code.
      Uses file: memory_errors.c (Files used in the Practice question at the end of the document: fileread_data.txt, fileread_test.c)
      Book recommended by Dr. Brezeale and Scott that explains Valgrind (and other topics such as how to make makefiles): "Intermediate C Programming" by Lu, Yung-Hsiang, isbn: 9781498711630. This book is NOT required and we will not make any references to it.
    4. diff checker
  2. IDEs (remember that the code must eventually be compiled and run on omega or VM.)
  3. Online IDEs:
  4. How to: Work at Google — Example Coding/Engineering Interview (Discusses the Two Sum problem from LeetCode)
  5. Extra, advanced: Memory usage when using classes from the language library. - Java Performance Tuning Guide by Mikhail Vorontsov. The article links to other useful articles. Challenging article. Be aware of these issues and decide when to use a library implementation and when to make your own.

Code for some of the data structures we cover in class

  1. Linked Lists list.h, list.c,
    test_list.c - Builds a list with integers from the user (stops when a non-integer was entered). Should be compiled with list.c.
    Sample compilation:
    	compile: gcc test_list.c list.c 		
    	run:     ./a.out 		

    Sample compilation with Valgrind (reports memory erros AND line numbers). You must COMPILE with the -g flag (so gcc -g, not just gcc).
    If you change the code, before rerunning Valgrind, recompile (with the gcc command to create the new a.out file).
    See above Minimal Valgrind Tutorial - for examples of Valgrind output for correct code (with no memory errors) and code with memory errors.
      	compile: gcc -g test_list.c list.c 		
    	run (with user input):    valgrind --leak-check=full ./a.out
    	run (with input redirection from file data1.txt, BUT NOT APPLICABLE HERE):    valgrind --leak-check=full ./a.out < data1.txt 						

  2. Graphs

Coding resources

  1. Video channels that cover algorithms, data structures and some coding:
  2. Learn/Practice C
    1. Online programming platforms.
      • LeetCode - problems tagged with difficulty level and topic. Multiple Categories (Algorithms, Databases, Shell, Concurency). (Recommended by students and TAs.)
      • HackerRank good from beginner to advanced. Has problems with more challanging test cases (e.g. large size input).
      • Geeksforgeeks has problem of the day and possibly more unlocked problems
      • other: codewars , code chef, binarysearch.io (I did not try it, they say you can "create a room, invite your friends, and race to finish the problems." )
    2. Learn C
      • tutotialspoint:
        • Learn C
        • Learn C by Example - I like this because it is based on problem-solving. It also discusses the logic and the pseudo-code. Even if you know C, this is a good place for practice
      • review/crash course
        • Crash course on C (text webpage) - brief description, code examples, drawings and explanations
        • Video review of C (3 hrs 46 min) - student quote: "I found this to be very helpful overall in review for C" . I find it did not go in detail enough, but it is a quick review for C syntax.
        • 10 hours C course by Caleb Curry - recommended in Fall 2023 by a transfer student that had not taken any C course (had taken Java and ?C++?). He skipped over some parts at first, but then he returned and watched it all as he had trouble understanding some of the later videos. [I did not watch it all, but as far as I watched it looked good and explained important details concepts (e.g. correct type casting). Note that there may be a mistake at minute 5:18 in "Evaluating Complex conditionals" - !(x>y) || (x!=y) ----> (x ≤ y) || (x!=y) -> says x!=y is redundant, but it is not. It allows x>y combinations ]
      • tutorials, video channels, books
      • other:
        • step-by-step Code visualization Step through code and see memory changes. Limitation: for non-trivial cases of dynamic memory shows incorrect/misleading memory image. Select C language.
        • Problems and solutions in C by topic and from basic (variable declaration) to file handling, arrays, recursion; good for beginners.
    3. DEBUGGING and COMMON BUGS. Check especially bugs related to strings, memory access and pointer and memory allocation.
    4. Pointers vs arrays
      1. pointer cheat sheet
      2. pointer to an array vs array of pointers
      3. pointer vs array
      4. pass 2D array as a parameter to a function
    5. Stack vs Heap memory - What is the difference between the stack and the heap? answer on ProgrammerInterview.com
      (List of DP problems on LeetCode: https://leetcode.com/discuss/general-discussion/491522/dynamic-programming-questions-thread)
  3. Issues that come up in homework:
    1. See above links and references for reinforcing your understanding of C and lists of common bugs.
    2. To compile code (e.g. on omega) using C99 (better than the default for omega) use: -std=c99
      gcc -g -std=c99 myProgr.c
    3. Debugging skills :
      1. Have a clear picture of what you want to do in your program
      2. Have a clear picture (and actually draw on paper) how the data is represented and how it changes throughout the program.
        Example 1: if you copy a string, what is the destination? An already allocated array (e.g. char buff[100]) or a pointer and if so, does it point to valid memory (previously allocated with malloc()/calloc())?
        Example 2: Draw the picture for the data below and show the changes that happen throughout the program.
        char* table[10];
        char buff[100];
        for(int i = 0; i<10; i++){
        	printf("%s", "Enter a string: ");
        	scanf("%s", buff);
        	table[i] = buff;
      3. Test often
      4. Do not make more or less random changes
      5. Start from a simple example that works. E.g.: you need to read data from a file and you do not know how to do it (or the code that you wrote does not work). Let that be and implement a small example that works (e.g. something you did in CSE 1320, or you got it from the web). Even if the file is not in the format you want, it still helps. Once you have that working, you can focus on how to gradually change that code so that it works for your type of file. TEST AT EVERY STEP!
      6. Read the manual for the C functions you use and take the time to try out their different behaviours, even if it appears to not be directly relevant to you homework .
    4. Reading from a file
      1. Read from the file and store data into an array of same size (exactly as many rows in the array as lines in the file)
      2. Read [arrays] from a file that has a specific format. E.g.:
        N Min Max
        val1 val2 val3.... valN
        where N indicates how many numbers will be on the next line separated by a space, and Min, Max give the range for those values (Min ≤ vali ≤ Max). E.g.
        7 0 25
        6 21 9 3 15 0 9
    5. String-related issues
      • Tokenizing a string (or a line read from a file). Possible methods:
      • allocating enough space to copy a string: malloc(strlen(s) + 1) (use +1 for \0)
      • "cleaning" a string: e.g. assume all the strings you get have 3 extra characters at the end that you want to get rid of. What do you do?
      • identifying and copying parts of a string into another one:
        Write a method that takes as argument one string and prints all possible substrings of a string or
        Write a method that takes as argument one string and returns an array with all substrings of the given string. Make the array rectangular or 'fit' (use exactly as much space as needed for each substring).
    6. How to pass a 2D array as a parameter in C (geeksforgeeks)
    7. Pointers
    8. Linked Lists
    9. Binary trees practice (problems and solutions)- Stanford Library

    1. You can check this video
    2. See section 1 from this page.
    3. Or this page.
    4. You can do a Google search. E.g. : "how do I run C code with file redirection?" (that is how I got the links above)
    5. Here is my example showing using redirected input with your C programs. Download and run (as shown below) this program and the data file: user_input.c, hello_data1.txt
      gcc -o userimp user_input.c
      Run one way (it will get the input from the user):
      Run another way (it will get the input with file redirection). Do not change the code or anything else. make sure 
       that the executable and hello_data1.txt are in the same folder:
      ./userimp.exe < hello_data1.txt	
      You should get the output:
      Please enter a word (less than 100 letters):Please enter another word (less than 100 letters):Please enter another word (less than 100 letters):You entered first: elephant
      ByeYou entered second: house
      ByeYou entered third: 3
      Another sample run 
      ./userimp.exe < hello_data2.txt
      You should get the output:
      Please enter a word (less than 100 letters):Please enter another word (less than 100 letters):Please enter another word (less than 100 letters):You entered first: elephant
      ByeYou entered second: house
      ByeYou entered third: 3
  5. Separate compilation and linking on omega:
    gcc -c hello.c
    hello.c  hello.o
    gcc -o hello.exe hello.o
    hello.c  hello.exe  hello.o
    Hello. The program is running fine.	
    Articles on compile vs link:
    1. GCC and Make Compiling, Linking and Building C/C++ Applications - See especially sections: "Compile and Link Separately" (g++ -c for compilation only and then linking) and "1.7 GCC Compilation Process"
    2. Compiling and Linking - short article, recommends using the term "build" instead of "compile" going from code to executable.