This repository includes example C programs for students in BU's ENG EK 125 course that I'm a teaching assistant for. These focus on strings, functions, pointers, and simple linked lists. The hope is that these can serve as supplemental resources for the students who wish to see more examples.
The C programs in this repo cover the following topics:
- math_intro.c shows example math operations in C
- RanIntArray.c shows running sum initialization and array creation
- baseball_stats.c creates a struct and stores baseball stats for a 25-man roster; also shows examples of i/o, flushing the input buffer, and selection statements
- trav_ex.c is an example of traversing a linked list
- strprac.c shows examples of using string functions in the string header file
- LL_Fun_with_Delete.c shows a general example of code to delete any element in a linked list, no matter where it is
- LL_Join.c illustrates how to combine two linked lists together
- LL_Add_to_Beginning.c describes how to add an item to the beginning of a linked list within int main()
- draw_triangle.c asks the user for a character input then draws a 45-45-90 triangle with that character using nested for loops
- Make_Pntrs.c is an example of initializing pointer variables and using a function to insert data into spaces allocated
- LL_RandomInt.c is an example of initializing a linked list with random integers
The PDF notes in this repo:
- General C Notes: goes over general programming concepts in C
- Intro to Dynamic Memory Allocation & Linked Lists in C: goes over DMA, pointers, and basic linked lists
How to run these programs in Terminal
Using gcc as the compiler:
-
Open Terminal
-
Navigate to the directory the .c file is in (use cd to change directory)
-
Type the following:
- gcc -o custom_name cfilename.c (then press enter/return)
- ./custom_name (then press enter/return)
For example:
- gcc -o makepointers Make_Pntrs.c (then press enter/return)
- ./makepointers (then press enter/return)
If you need more help with Terminal and navigating to the directory where your .c file is, follow this documentation I made for the course I TA for. If more help is needed, feel free to contact me directly.