| Main & Syllabi | Schedule | Slides | Daily | Homework | Quizzes | Code | Office hours for instructor and TAs |

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, Valgrind, debugger

  1. omega or VM - Your code must compile and run on either omega or VM. 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, Valgrind
    1. omega server: Brief instructions for Windows and Mac, Detailed instructions for Unix . In order to use omega, you need to be connected with Secure Pulse VPN to UTA, and for VPN authentication you need to have multi-factor authentication. Please follow the OIT instructions on setting this up *the link in the Unix instructions is broken): UTA OIT multi-factor authentication. If you already set it up, you do not need to redo it.
    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 files: memory_errors.c,fileread_data.txt, fileread_test.c, data.txt
      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.) If you do not have an IDE already, you can use Code::Blocks for Windows. See:
  3. Online IDEs:

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). Note that you must COMPILE with the -g flag (so gcc -g, not just gcc):
      		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 		
    See above Minimal Valgrind Tutorial - for a examples of Valgrind output for correct code (with no memory errors) and code with memory errors.

  2. Graphs

Coding resources

The majority of references posted on this page were recommended by students. Thank you for your contributions! I learnt a lot from you! - Alexandra
  1. Coding Interview Problems
    1. How to: Work at Google — Example Coding/Engineering Interview (Discusses the Two Sum problem from LeetCode)
    2. Daily Coding Problem - they send you a daily email with a problem. With the free subscription often times the problems are not very specific (e.g. what time and space complexity is expected from a solution, or how general the problem is) but it keeps you in the game and gives you a nice problem to think about.
  2. Discussions about memory usage when using classes from the language library. Be aware of these issues and decide when to use a library implementation and when to make your own.
    1. Java Performance Tuning Guide by Mikhail Vorontsov. The article links to other useful articles. (challenging article)
  3. Video channels:
  4. Learn/Practice C
    1. Learn C
      • Darin Brezeale was nominated best teaching practices at UTA and was highly appreciated by students. He has now a video channel where he covers C and other topics. I STRONGLY recommend watching his videos if you need to learn C or review it.
        • COMMON ERRORS IN C - WATCH THIS VIDEO! It is very useful and only 32 minutes long. It shows and explains C errors that I also see in homework code for CSE3318 (especially mistakes numbers 5 and on). They are due to not know the exact behavior of the instructions written (as they are). The explanations are very good and to the point. I recommend EVERY student (even those making an A in programming classes) to watch it. At the very least it can serve as a review and you will avoid having those bugs in your code, or if you get them, you will recognize them faster and know how to approach them.
        • Darin Brezeale video channel I recommend not skipping but playing at a higher speed if you know the particular aspect of that topic. I recommend watching at least the videos on arrays, pointers and reading from files.
        • post on pointers in C
        • Discrete Structures playlist
      • Video review of C (3 hrs 46 min) - student quote: "I found this to be very helpful overall in review for C"
      • Crash course on C (webpage text)
      • Good for beginers: Problems and solutions in C by topic and from basic (variable declaration) to file handling, arrays, recursion
      • C tutorial (TutorialsPoint) - goes over setting up the envirement, can read page by page, has videos.
      • C Programming LanguageTutorial from GeegsforGeeks - Explains code line by line, organized by topics
      • Book (one of many out there): Intermediate C Programming. - recommended by Dr. Darin Brezeale to be trully at intermediate level.
    2. Online platforms where you can solve problems. You can edit the code online and the paltform automatially test it for correctness.
    3. DEBUGGING and COMMON BUGS. below are some good pages with bug discussion. Check especially bugs related to strings, memory access and pointer and memory allocation. (I did not check if the resources below are complementary or if they cover the same bugs.)
    4. Pointers vs arrays
      1. pointer cheat sheet
      2. pointer to an arrays 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)
  5. 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 that 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
      Linked Lists Basics (highlights: pages12-15).
      Linked Lists Problems. - Has problems and solutions.
    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
  7. 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.