├── 00_hello ├── hello.txt ├── grade.txt └── README ├── 01_apple ├── fruit.txt ├── grade.txt └── README ├── 08_testing ├── input.1 ├── input.2 ├── input.3 ├── input.4 ├── isPrime-broken1 ├── isPrime-broken2 ├── isPrime-broken3 ├── isPrime-broken4 ├── isPrime-correct ├── grade.txt └── README ├── 34_put_together ├── kv.c ├── kv.h ├── counts.c ├── counts.h ├── outname.c ├── outname.h ├── list2a.txt ├── list1a.txt.ans ├── list1a.txt.counts ├── list2a.txt.ans ├── list2c.txt.ans ├── kv.o ├── list2a.txt.counts ├── list2b.txt.ans ├── list2b.txt.counts ├── list2c.txt.counts ├── main.o ├── counts.o ├── list1b.txt.ans ├── list1b.txt.counts ├── outname.o ├── count_values ├── list1b.txt ├── list2c.txt ├── list2b.txt ├── list1a.txt ├── kvs2.txt ├── kvs1.txt ├── Makefile ├── README ├── grade.txt └── main.c ├── c3prj1_deck ├── cards.c ├── cards.h ├── cards.o ├── deck.o ├── deck-c4.o ├── test-deck ├── test-deck.o ├── Makefile ├── grade.txt ├── deck.h └── deck.c ├── c3prj2_eval ├── cards.c ├── cards.h ├── deck.c ├── deck.h ├── tests.txt ├── cards.o ├── deck.o ├── eval.o ├── input.o ├── deck-c4.o ├── eval-c4.o ├── future.o ├── test-eval ├── test-eval.o ├── eval.h ├── Makefile └── grade.txt ├── c4prj1_deck ├── cards.c ├── cards.h ├── deck.c ├── deck.h ├── eval.c ├── eval.h └── grade.txt ├── c4prj2_input ├── cards.c ├── cards.h ├── deck.c ├── deck.h ├── eval.c ├── eval.h ├── future.h ├── input.h ├── grade.txt ├── future.c ├── #input.c# └── input.c ├── c4prj3_finish ├── deck.c ├── deck.h ├── eval.c ├── eval.h ├── cards.c ├── cards.h ├── future.c ├── future.h ├── input.c ├── input.h ├── provided-tests │ ├── test01.txt │ ├── test02.txt │ ├── test03.txt │ ├── test04.txt │ ├── test05.txt │ ├── test06.txt │ ├── test07.txt │ ├── test08.txt │ ├── test09.txt │ ├── test10.txt │ ├── test11.txt │ ├── test12.txt │ ├── test13.txt │ ├── test14.txt │ ├── test15.txt │ ├── test16.txt │ └── answers.txt ├── Makefile ├── main.c └── grade.txt ├── 10_gdb ├── input.txt ├── game ├── grade.txt ├── game.c └── README ├── 30_sort_lines ├── input.txt ├── input2.txt ├── sortLines ├── Makefile ├── grade.txt ├── README └── sortLines.c ├── 26_tests_matrix_input ├── input2.txt ├── input5.txt ├── tests.txt ├── input0.txt ├── input1.txt ├── input6.txt ├── input4.txt ├── input3.txt ├── run_all.sh ├── grade.txt ├── README └── next-README ├── 23_power_rec ├── test-power.c ├── test ├── Makefile ├── power.c ├── README └── grade.txt ├── 28_fix_vg_encr ├── input.txt ├── input.txt.enc ├── encrypt ├── Makefile ├── grade.txt ├── README └── encrypt.c ├── 21_read_rec1 ├── answer.txt ├── Makefile ├── test ├── README ├── grade.txt └── test.c ├── c2prj2_testing ├── example.txt ├── tests.txt ├── test-eval ├── run_all.sh └── grade.txt ├── c2prj1_cards ├── my-test-main.c ├── deck.o ├── eval.o ├── main.o ├── poker ├── cards.o ├── deck-c4.o ├── eval-c4.o ├── future.o ├── input.o ├── Makefile ├── cards.h ├── grade.txt └── cards.c ├── 11_read_ptr1 ├── Makefile ├── test ├── answer.txt ├── correct.txt ├── grade.txt ├── README └── test.c ├── 12_read_ptr2 ├── Makefile ├── answer.txt ├── test ├── grade.txt ├── README └── test.c ├── 13_read_arr1 ├── Makefile ├── test ├── answer.txt ├── grade.txt ├── README └── test.c ├── 17_read_arr2 ├── Makefile ├── answer.txt ├── test ├── grade.txt ├── README └── test.c ├── 24_read_arr3 ├── Makefile ├── test ├── res.txt ├── answer.txt ├── grade.txt ├── README └── test.c ├── 32_kvs ├── kv.o ├── kv_test ├── kv_test.o ├── test.txt ├── Makefile ├── kv_test.c ├── kv.h ├── grade.txt └── kv.c ├── 04_compile ├── hello ├── hello.c ├── grade.txt └── README ├── 06_rect ├── Makefile ├── rectangle ├── grade.txt ├── res.txt ├── rectangle_ans.txt └── README ├── 14_array_max ├── Makefile ├── arrayMax ├── README ├── grade.txt └── arrayMax.c ├── 18_reverse_str ├── Makefile ├── reverse ├── ans.txt ├── reverse_ans.txt ├── grade.txt ├── README └── reverse.c ├── 25_break_encr ├── Makefile ├── breaker ├── grade.txt ├── breaker.c └── README ├── 05_squares ├── squares ├── squares_test.o ├── 3_5_8_2.txt ├── ans_3_5_8_2.txt ├── ans_9_2_3_4.txt ├── ans_5_2_4_6.txt ├── squares.c └── README ├── 19_bits_arr ├── Makefile ├── numToBits ├── ans.txt ├── bits_ans.txt ├── grade.txt ├── numToBits.c └── README ├── 33_counts ├── counts.o ├── counts_test ├── counts_test.o ├── Makefile ├── counts_test.c ├── counts.h ├── grade.txt ├── counts.c └── README ├── 07_retirement ├── Makefile ├── retirement ├── retirement.c └── README ├── 16_subseq ├── test-subseq ├── grade.txt ├── maxSeq.c ├── test-subseq.c └── README ├── 20_rot_matrix ├── rotate ├── read-matrix.o ├── Makefile ├── my_ans.txt ├── sample.out ├── sample.txt ├── grade.txt ├── rotate.c └── README ├── 29_outname ├── outname.o ├── outname_test ├── outname_test.o ├── outname.h ├── Makefile ├── outname_test.c ├── outname.c ├── grade.txt └── README ├── 15_tests_subseq ├── test-subseq ├── test-subseq.c ├── run_all.sh ├── README ├── grade.txt └── next-README ├── 22_tests_power ├── test-power ├── test-power.c ├── next-README ├── run_all.sh ├── grade.txt └── README ├── 31_minesweeper ├── minesweeper ├── Makefile ├── grade.txt └── README ├── README.md ├── 27_matrix_input ├── sample.out ├── sample.txt ├── grade.txt ├── README └── rotateMatrix.c ├── 09_testing2 ├── tests.txt ├── run_all.sh └── README ├── README ├── 02_code1 ├── code1.c ├── test.sh ├── README └── grade.txt ├── .gitignore ├── 03_code2 ├── grade.txt ├── test.sh ├── code2.c └── README └── and_beyond └── README /00_hello/hello.txt: -------------------------------------------------------------------------------- 1 | hello 2 | -------------------------------------------------------------------------------- /01_apple/fruit.txt: -------------------------------------------------------------------------------- 1 | apple 2 | -------------------------------------------------------------------------------- /08_testing/input.1: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /08_testing/input.2: -------------------------------------------------------------------------------- 1 | 101 2 | -------------------------------------------------------------------------------- /08_testing/input.3: -------------------------------------------------------------------------------- 1 | 0.1 2 | -------------------------------------------------------------------------------- /08_testing/input.4: -------------------------------------------------------------------------------- 1 | -1 2 | -------------------------------------------------------------------------------- /34_put_together/kv.c: -------------------------------------------------------------------------------- 1 | ../32_kvs/kv.c -------------------------------------------------------------------------------- /34_put_together/kv.h: -------------------------------------------------------------------------------- 1 | ../32_kvs/kv.h -------------------------------------------------------------------------------- /c3prj1_deck/cards.c: -------------------------------------------------------------------------------- 1 | ../c2prj1_cards/cards.c -------------------------------------------------------------------------------- /c3prj1_deck/cards.h: -------------------------------------------------------------------------------- 1 | ../c2prj1_cards/cards.h -------------------------------------------------------------------------------- /c3prj2_eval/cards.c: -------------------------------------------------------------------------------- 1 | ../c2prj1_cards/cards.c -------------------------------------------------------------------------------- /c3prj2_eval/cards.h: -------------------------------------------------------------------------------- 1 | ../c2prj1_cards/cards.h -------------------------------------------------------------------------------- /c3prj2_eval/deck.c: -------------------------------------------------------------------------------- 1 | ../c3prj1_deck/deck.c -------------------------------------------------------------------------------- /c3prj2_eval/deck.h: -------------------------------------------------------------------------------- 1 | ../c3prj1_deck/deck.h -------------------------------------------------------------------------------- /c4prj1_deck/cards.c: -------------------------------------------------------------------------------- 1 | ../c2prj1_cards/cards.c -------------------------------------------------------------------------------- /c4prj1_deck/cards.h: -------------------------------------------------------------------------------- 1 | ../c2prj1_cards/cards.h -------------------------------------------------------------------------------- /c4prj1_deck/deck.c: -------------------------------------------------------------------------------- 1 | ../c3prj1_deck/deck.c -------------------------------------------------------------------------------- /c4prj1_deck/deck.h: -------------------------------------------------------------------------------- 1 | ../c3prj1_deck/deck.h -------------------------------------------------------------------------------- /c4prj1_deck/eval.c: -------------------------------------------------------------------------------- 1 | ../c3prj2_eval/eval.c -------------------------------------------------------------------------------- /c4prj1_deck/eval.h: -------------------------------------------------------------------------------- 1 | ../c3prj2_eval/eval.h -------------------------------------------------------------------------------- /c4prj2_input/cards.c: -------------------------------------------------------------------------------- 1 | ../c2prj1_cards/cards.c -------------------------------------------------------------------------------- /c4prj2_input/cards.h: -------------------------------------------------------------------------------- 1 | ../c2prj1_cards/cards.h -------------------------------------------------------------------------------- /c4prj2_input/deck.c: -------------------------------------------------------------------------------- 1 | ../c3prj1_deck/deck.c -------------------------------------------------------------------------------- /c4prj2_input/deck.h: -------------------------------------------------------------------------------- 1 | ../c3prj1_deck/deck.h -------------------------------------------------------------------------------- /c4prj2_input/eval.c: -------------------------------------------------------------------------------- 1 | ../c3prj2_eval/eval.c -------------------------------------------------------------------------------- /c4prj2_input/eval.h: -------------------------------------------------------------------------------- 1 | ../c3prj2_eval/eval.h -------------------------------------------------------------------------------- /c4prj3_finish/deck.c: -------------------------------------------------------------------------------- 1 | ../c3prj1_deck/deck.c -------------------------------------------------------------------------------- /c4prj3_finish/deck.h: -------------------------------------------------------------------------------- 1 | ../c3prj1_deck/deck.h -------------------------------------------------------------------------------- /c4prj3_finish/eval.c: -------------------------------------------------------------------------------- 1 | ../c3prj2_eval/eval.c -------------------------------------------------------------------------------- /c4prj3_finish/eval.h: -------------------------------------------------------------------------------- 1 | ../c3prj2_eval/eval.h -------------------------------------------------------------------------------- /10_gdb/input.txt: -------------------------------------------------------------------------------- 1 | 464384013 2 | 938257400 3 | -------------------------------------------------------------------------------- /30_sort_lines/input.txt: -------------------------------------------------------------------------------- 1 | B 2 | D 3 | C 4 | A 5 | -------------------------------------------------------------------------------- /30_sort_lines/input2.txt: -------------------------------------------------------------------------------- 1 | B 2 | C 3 | D 4 | A 5 | -------------------------------------------------------------------------------- /34_put_together/counts.c: -------------------------------------------------------------------------------- 1 | ../33_counts/counts.c -------------------------------------------------------------------------------- /34_put_together/counts.h: -------------------------------------------------------------------------------- 1 | ../33_counts/counts.h -------------------------------------------------------------------------------- /34_put_together/outname.c: -------------------------------------------------------------------------------- 1 | ../29_outname/outname.c -------------------------------------------------------------------------------- /34_put_together/outname.h: -------------------------------------------------------------------------------- 1 | ../29_outname/outname.h -------------------------------------------------------------------------------- /c3prj2_eval/tests.txt: -------------------------------------------------------------------------------- 1 | ../c2prj2_testing/tests.txt -------------------------------------------------------------------------------- /c4prj3_finish/cards.c: -------------------------------------------------------------------------------- 1 | ../c2prj1_cards/cards.c -------------------------------------------------------------------------------- /c4prj3_finish/cards.h: -------------------------------------------------------------------------------- 1 | ../c2prj1_cards/cards.h -------------------------------------------------------------------------------- /c4prj3_finish/future.c: -------------------------------------------------------------------------------- 1 | ../c4prj2_input/future.c -------------------------------------------------------------------------------- /c4prj3_finish/future.h: -------------------------------------------------------------------------------- 1 | ../c4prj2_input/future.h -------------------------------------------------------------------------------- /c4prj3_finish/input.c: -------------------------------------------------------------------------------- 1 | ../c4prj2_input/input.c -------------------------------------------------------------------------------- /c4prj3_finish/input.h: -------------------------------------------------------------------------------- 1 | ../c4prj2_input/input.h -------------------------------------------------------------------------------- /26_tests_matrix_input/input2.txt: -------------------------------------------------------------------------------- 1 | \n\n\n\n\n 2 | 3 | -------------------------------------------------------------------------------- /23_power_rec/test-power.c: -------------------------------------------------------------------------------- 1 | ../22_tests_power/test-power.c -------------------------------------------------------------------------------- /28_fix_vg_encr/input.txt: -------------------------------------------------------------------------------- 1 | An example 2 | Of the input. 3 | -------------------------------------------------------------------------------- /28_fix_vg_encr/input.txt.enc: -------------------------------------------------------------------------------- 1 | hu lehtwsl 2 | vm aol puwba. 3 | -------------------------------------------------------------------------------- /21_read_rec1/answer.txt: -------------------------------------------------------------------------------- 1 | a=29, b=7 2 | a=2, b=9 3 | a=0, b=2 4 | 297 5 | -------------------------------------------------------------------------------- /c2prj2_testing/example.txt: -------------------------------------------------------------------------------- 1 | 0c 0s 8s 7d 6d 6s 5c; Js 0s 8s 7d 6s 5c 4c 2 | -------------------------------------------------------------------------------- /34_put_together/list2a.txt: -------------------------------------------------------------------------------- 1 | Will Riker 2 | Worf 3 | Tasha Yar 4 | Guinan 5 | Ro Laren 6 | -------------------------------------------------------------------------------- /c2prj1_cards/my-test-main.c: -------------------------------------------------------------------------------- 1 | #include "cards.h" 2 | 3 | int main(void) { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /c4prj3_finish/provided-tests/test01.txt: -------------------------------------------------------------------------------- 1 | Qs Qc 7h 2h Qd 0c ?0 2 | Ks Kc 7h 2h Qd 0c ?0 3 | -------------------------------------------------------------------------------- /c4prj3_finish/provided-tests/test02.txt: -------------------------------------------------------------------------------- 1 | 0c 9d Qs Ad Ah 4d ?0 2 | Kh 4h Qs Ad Ah 4d ?0 3 | -------------------------------------------------------------------------------- /c4prj3_finish/provided-tests/test03.txt: -------------------------------------------------------------------------------- 1 | 0h 0d ?0 ?1 ?2 ?3 ?4 2 | Ah 9h ?0 ?1 ?2 ?3 ?4 3 | -------------------------------------------------------------------------------- /c4prj3_finish/provided-tests/test04.txt: -------------------------------------------------------------------------------- 1 | Kc Qc ?0 ?1 ?2 ?3 ?4 2 | 4s 2s ?0 ?1 ?2 ?3 ?4 3 | -------------------------------------------------------------------------------- /c4prj3_finish/provided-tests/test05.txt: -------------------------------------------------------------------------------- 1 | Kc Qc 4d 8s 8d ?0 ?1 2 | 4s 2s 4d 8s 8d ?0 ?1 3 | -------------------------------------------------------------------------------- /c4prj3_finish/provided-tests/test06.txt: -------------------------------------------------------------------------------- 1 | Kc Qc 4d 8s 8d 9c ?0 2 | 4s 2s 4d 8s 8d 9c ?0 3 | -------------------------------------------------------------------------------- /c4prj3_finish/provided-tests/test07.txt: -------------------------------------------------------------------------------- 1 | Kc Qc 4d 8s 8d 9c 9s 2 | 4s 2s 4d 8s 8d 9c 9s 3 | -------------------------------------------------------------------------------- /c4prj3_finish/provided-tests/test08.txt: -------------------------------------------------------------------------------- 1 | 7c 6h ?4 ?3 ?2 ?1 ?0 2 | 7h 6c ?4 ?3 ?2 ?1 ?0 3 | -------------------------------------------------------------------------------- /c4prj3_finish/provided-tests/test09.txt: -------------------------------------------------------------------------------- 1 | 7c 6h Jh 4c 2h ?1 ?0 2 | 7h 6c Jh 4c 2h ?1 ?0 3 | -------------------------------------------------------------------------------- /c4prj3_finish/provided-tests/test10.txt: -------------------------------------------------------------------------------- 1 | 7c 6h Jh 4c 2h 8h ?0 2 | 7h 6c Jh 4c 2h 8h ?0 3 | -------------------------------------------------------------------------------- /c4prj3_finish/provided-tests/test11.txt: -------------------------------------------------------------------------------- 1 | 0c 6d ?4 ?3 ?2 ?1 ?0 2 | Js 4c ?4 ?3 ?2 ?1 ?0 3 | -------------------------------------------------------------------------------- /c4prj3_finish/provided-tests/test12.txt: -------------------------------------------------------------------------------- 1 | 0c 6d 0s 7d 5c ?1 ?0 2 | Js 4c 0s 7d 5c ?1 ?0 3 | -------------------------------------------------------------------------------- /c4prj3_finish/provided-tests/test13.txt: -------------------------------------------------------------------------------- 1 | 0c 6d 0s 7d 5c 8s ?0 2 | Js 4c 0s 7d 5c 8s ?0 3 | -------------------------------------------------------------------------------- /11_read_ptr1/Makefile: -------------------------------------------------------------------------------- 1 | test: test.c 2 | gcc -o test -Wall -Werror -pedantic -std=gnu99 test.c 3 | -------------------------------------------------------------------------------- /12_read_ptr2/Makefile: -------------------------------------------------------------------------------- 1 | test:test.c 2 | gcc -o test -Wall -Werror --pedantic -std=gnu99 test.c 3 | -------------------------------------------------------------------------------- /13_read_arr1/Makefile: -------------------------------------------------------------------------------- 1 | test:test.c 2 | gcc -o test -Wall -Werror --pedantic -std=gnu99 test.c 3 | -------------------------------------------------------------------------------- /17_read_arr2/Makefile: -------------------------------------------------------------------------------- 1 | test: test.c 2 | gcc -o test -Wall -Werror -pedantic -std=gnu99 test.c 3 | -------------------------------------------------------------------------------- /21_read_rec1/Makefile: -------------------------------------------------------------------------------- 1 | test:test.c 2 | gcc -o test -Wall -Werror --pedantic -std=gnu99 test.c 3 | -------------------------------------------------------------------------------- /24_read_arr3/Makefile: -------------------------------------------------------------------------------- 1 | test:test.c 2 | gcc -o test -Wall -Werror --pedantic -std=gnu99 test.c 3 | -------------------------------------------------------------------------------- /c4prj3_finish/provided-tests/test14.txt: -------------------------------------------------------------------------------- 1 | Kh As ?0 ?1 ?2 2 | Kh As ?0 ?1 ?2 3 | 0s 9c ?1 ?2 ?3 4 | -------------------------------------------------------------------------------- /10_gdb/game: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/10_gdb/game -------------------------------------------------------------------------------- /32_kvs/kv.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/32_kvs/kv.o -------------------------------------------------------------------------------- /12_read_ptr2/answer.txt: -------------------------------------------------------------------------------- 1 | **r = 12 2 | **s = 80 3 | x = 92 4 | *p = -7 5 | *q = 75 6 | a = 75 7 | b = -7 8 | -------------------------------------------------------------------------------- /32_kvs/kv_test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/32_kvs/kv_test -------------------------------------------------------------------------------- /04_compile/hello: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/04_compile/hello -------------------------------------------------------------------------------- /06_rect/Makefile: -------------------------------------------------------------------------------- 1 | rectangle: rectangle.c 2 | gcc -o rectangle -pedantic -std=gnu99 -Wall -Werror rectangle.c 3 | -------------------------------------------------------------------------------- /06_rect/rectangle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/06_rect/rectangle -------------------------------------------------------------------------------- /11_read_ptr1/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/11_read_ptr1/test -------------------------------------------------------------------------------- /12_read_ptr2/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/12_read_ptr2/test -------------------------------------------------------------------------------- /13_read_arr1/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/13_read_arr1/test -------------------------------------------------------------------------------- /14_array_max/Makefile: -------------------------------------------------------------------------------- 1 | arrayMax: arrayMax.c 2 | gcc -o arrayMax -pedantic -std=gnu99 -Wall -Werror arrayMax.c 3 | -------------------------------------------------------------------------------- /17_read_arr2/answer.txt: -------------------------------------------------------------------------------- 1 | p 2 | l 3 | n 4 | a 5 | bannana has nana 3 characters into it! 6 | r 7 | o 8 | fduurw 9 | -------------------------------------------------------------------------------- /17_read_arr2/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/17_read_arr2/test -------------------------------------------------------------------------------- /18_reverse_str/Makefile: -------------------------------------------------------------------------------- 1 | reverse: reverse.c 2 | gcc -o reverse -pedantic -std=gnu99 -Wall -Werror reverse.c 3 | -------------------------------------------------------------------------------- /21_read_rec1/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/21_read_rec1/test -------------------------------------------------------------------------------- /23_power_rec/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/23_power_rec/test -------------------------------------------------------------------------------- /24_read_arr3/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/24_read_arr3/test -------------------------------------------------------------------------------- /25_break_encr/Makefile: -------------------------------------------------------------------------------- 1 | breaker:breaker.c 2 | gcc -o breaker -Wall -Werror --pedantic -std=gnu99 breaker.c 3 | -------------------------------------------------------------------------------- /32_kvs/kv_test.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/32_kvs/kv_test.o -------------------------------------------------------------------------------- /34_put_together/list1a.txt.ans: -------------------------------------------------------------------------------- 1 | red: 3 2 | green: 1 3 | blue: 1 4 | purple: 2 5 | yellow: 2 6 | : 2 7 | -------------------------------------------------------------------------------- /05_squares/squares: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/05_squares/squares -------------------------------------------------------------------------------- /19_bits_arr/Makefile: -------------------------------------------------------------------------------- 1 | numToBits: numToBits.c 2 | gcc -o numToBits -pedantic -std=gnu99 -Wall -Werror numToBits.c 3 | -------------------------------------------------------------------------------- /33_counts/counts.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/33_counts/counts.o -------------------------------------------------------------------------------- /34_put_together/list1a.txt.counts: -------------------------------------------------------------------------------- 1 | red: 3 2 | green: 1 3 | blue: 1 4 | purple: 2 5 | yellow: 2 6 | : 2 7 | -------------------------------------------------------------------------------- /34_put_together/list2a.txt.ans: -------------------------------------------------------------------------------- 1 | Commander: 1 2 | Lt. Commander: 1 3 | Lieutenant: 1 4 | Bartender: 1 5 | Ensign: 1 6 | -------------------------------------------------------------------------------- /34_put_together/list2c.txt.ans: -------------------------------------------------------------------------------- 1 | Lt. Commander: 2 2 | Captain: 1 3 | Lieutenant: 1 4 | Ensign: 1 5 | : 3 6 | -------------------------------------------------------------------------------- /c2prj1_cards/deck.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c2prj1_cards/deck.o -------------------------------------------------------------------------------- /c2prj1_cards/eval.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c2prj1_cards/eval.o -------------------------------------------------------------------------------- /c2prj1_cards/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c2prj1_cards/main.o -------------------------------------------------------------------------------- /c2prj1_cards/poker: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c2prj1_cards/poker -------------------------------------------------------------------------------- /c2prj2_testing/tests.txt: -------------------------------------------------------------------------------- 1 | 0c 0s 8s 7d 6d 6s 5c; Js 0s 8s 7d 6s 5c 4c 2 | Ad As Ah 1d Kh Ks Ac; Kc Kd Ah 9d Kh Ks Ac 3 | -------------------------------------------------------------------------------- /c3prj1_deck/cards.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c3prj1_deck/cards.o -------------------------------------------------------------------------------- /c3prj1_deck/deck.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c3prj1_deck/deck.o -------------------------------------------------------------------------------- /c3prj2_eval/cards.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c3prj2_eval/cards.o -------------------------------------------------------------------------------- /c3prj2_eval/deck.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c3prj2_eval/deck.o -------------------------------------------------------------------------------- /c3prj2_eval/eval.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c3prj2_eval/eval.o -------------------------------------------------------------------------------- /c3prj2_eval/input.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c3prj2_eval/input.o -------------------------------------------------------------------------------- /c4prj3_finish/provided-tests/test15.txt: -------------------------------------------------------------------------------- 1 | 9c 7h Js 3h 3d ?0 ?1 2 | Qs 5h Js 3h 3d ?0 ?1 3 | Jc 7c Js 3h 3d ?0 ?1 4 | -------------------------------------------------------------------------------- /07_retirement/Makefile: -------------------------------------------------------------------------------- 1 | retirement: retirement.c 2 | gcc -o retirement -pedantic -std=gnu99 -Wall -Werror retirement.c 3 | -------------------------------------------------------------------------------- /14_array_max/arrayMax: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/14_array_max/arrayMax -------------------------------------------------------------------------------- /16_subseq/test-subseq: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/16_subseq/test-subseq -------------------------------------------------------------------------------- /18_reverse_str/reverse: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/18_reverse_str/reverse -------------------------------------------------------------------------------- /19_bits_arr/numToBits: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/19_bits_arr/numToBits -------------------------------------------------------------------------------- /20_rot_matrix/rotate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/20_rot_matrix/rotate -------------------------------------------------------------------------------- /25_break_encr/breaker: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/25_break_encr/breaker -------------------------------------------------------------------------------- /28_fix_vg_encr/encrypt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/28_fix_vg_encr/encrypt -------------------------------------------------------------------------------- /29_outname/outname.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/29_outname/outname.o -------------------------------------------------------------------------------- /32_kvs/test.txt: -------------------------------------------------------------------------------- 1 | apple=red 2 | banana=yellow 3 | orange=orange 4 | grapes=purple 5 | carrot=orange 6 | eggplant=purple 7 | -------------------------------------------------------------------------------- /33_counts/counts_test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/33_counts/counts_test -------------------------------------------------------------------------------- /34_put_together/kv.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/34_put_together/kv.o -------------------------------------------------------------------------------- /34_put_together/list2a.txt.counts: -------------------------------------------------------------------------------- 1 | Commander: 1 2 | Lt. Commander: 1 3 | Lieutenant: 1 4 | Bartender: 1 5 | Ensign: 1 6 | -------------------------------------------------------------------------------- /34_put_together/list2b.txt.ans: -------------------------------------------------------------------------------- 1 | Captain: 1 2 | Lt. Commander: 3 3 | Lieutenant: 1 4 | Commander: 1 5 | : 2 6 | -------------------------------------------------------------------------------- /34_put_together/list2b.txt.counts: -------------------------------------------------------------------------------- 1 | Captain: 1 2 | Lt. Commander: 3 3 | Lieutenant: 1 4 | Commander: 1 5 | : 2 6 | -------------------------------------------------------------------------------- /34_put_together/list2c.txt.counts: -------------------------------------------------------------------------------- 1 | Lt. Commander: 2 2 | Captain: 1 3 | Lieutenant: 1 4 | Ensign: 1 5 | : 3 6 | -------------------------------------------------------------------------------- /34_put_together/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/34_put_together/main.o -------------------------------------------------------------------------------- /c2prj1_cards/cards.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c2prj1_cards/cards.o -------------------------------------------------------------------------------- /c2prj1_cards/deck-c4.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c2prj1_cards/deck-c4.o -------------------------------------------------------------------------------- /c2prj1_cards/eval-c4.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c2prj1_cards/eval-c4.o -------------------------------------------------------------------------------- /c2prj1_cards/future.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c2prj1_cards/future.o -------------------------------------------------------------------------------- /c2prj1_cards/input.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c2prj1_cards/input.o -------------------------------------------------------------------------------- /c3prj1_deck/deck-c4.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c3prj1_deck/deck-c4.o -------------------------------------------------------------------------------- /c3prj1_deck/test-deck: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c3prj1_deck/test-deck -------------------------------------------------------------------------------- /c3prj2_eval/deck-c4.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c3prj2_eval/deck-c4.o -------------------------------------------------------------------------------- /c3prj2_eval/eval-c4.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c3prj2_eval/eval-c4.o -------------------------------------------------------------------------------- /c3prj2_eval/future.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c3prj2_eval/future.o -------------------------------------------------------------------------------- /c3prj2_eval/test-eval: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c3prj2_eval/test-eval -------------------------------------------------------------------------------- /07_retirement/retirement: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/07_retirement/retirement -------------------------------------------------------------------------------- /11_read_ptr1/answer.txt: -------------------------------------------------------------------------------- 1 | In f, *a = 3, b = 4 2 | In g, x = 7, *y = 8 3 | Back in f, *a = 7, b = 0 4 | In main: x = 7, y = 4 5 | -------------------------------------------------------------------------------- /11_read_ptr1/correct.txt: -------------------------------------------------------------------------------- 1 | In f, *a = 3, b = 4 2 | In g, x = 7, *y = 8 3 | Back in f, *a = 7, b = 0 4 | In main: x = 7, y = 4 5 | -------------------------------------------------------------------------------- /13_read_arr1/answer.txt: -------------------------------------------------------------------------------- 1 | *p = 5 2 | Now *p = 16 3 | anArray[0] = 5 4 | anArray[1] = 42 5 | anArray[2] = 9 6 | anArray[3] = 12 7 | -------------------------------------------------------------------------------- /23_power_rec/Makefile: -------------------------------------------------------------------------------- 1 | test: test-power.c power.c 2 | gcc -o test -pedantic -std=gnu99 -Wall -Werror test-power.c power.c 3 | -------------------------------------------------------------------------------- /29_outname/outname_test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/29_outname/outname_test -------------------------------------------------------------------------------- /30_sort_lines/sortLines: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/30_sort_lines/sortLines -------------------------------------------------------------------------------- /33_counts/counts_test.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/33_counts/counts_test.o -------------------------------------------------------------------------------- /34_put_together/counts.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/34_put_together/counts.o -------------------------------------------------------------------------------- /34_put_together/list1b.txt.ans: -------------------------------------------------------------------------------- 1 | green: 2 2 | yellow: 1 3 | red: 3 4 | blue: 1 5 | orange: 1 6 | brown: 1 7 | : 1 8 | -------------------------------------------------------------------------------- /34_put_together/list1b.txt.counts: -------------------------------------------------------------------------------- 1 | green: 2 2 | yellow: 1 3 | red: 3 4 | blue: 1 5 | orange: 1 6 | brown: 1 7 | : 1 8 | -------------------------------------------------------------------------------- /c2prj2_testing/test-eval: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c2prj2_testing/test-eval -------------------------------------------------------------------------------- /c3prj1_deck/test-deck.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c3prj1_deck/test-deck.o -------------------------------------------------------------------------------- /c3prj2_eval/test-eval.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/c3prj2_eval/test-eval.o -------------------------------------------------------------------------------- /05_squares/squares_test.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/05_squares/squares_test.o -------------------------------------------------------------------------------- /08_testing/isPrime-broken1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/08_testing/isPrime-broken1 -------------------------------------------------------------------------------- /08_testing/isPrime-broken2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/08_testing/isPrime-broken2 -------------------------------------------------------------------------------- /08_testing/isPrime-broken3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/08_testing/isPrime-broken3 -------------------------------------------------------------------------------- /08_testing/isPrime-broken4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/08_testing/isPrime-broken4 -------------------------------------------------------------------------------- /08_testing/isPrime-correct: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/08_testing/isPrime-correct -------------------------------------------------------------------------------- /10_gdb/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 04:53:24 UTC 2018 2 | Your file matched the expected output 3 | 4 | Overall Grade: PASSED 5 | -------------------------------------------------------------------------------- /15_tests_subseq/test-subseq: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/15_tests_subseq/test-subseq -------------------------------------------------------------------------------- /20_rot_matrix/read-matrix.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/20_rot_matrix/read-matrix.o -------------------------------------------------------------------------------- /22_tests_power/test-power: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/22_tests_power/test-power -------------------------------------------------------------------------------- /24_read_arr3/res.txt: -------------------------------------------------------------------------------- 1 | x = 1 2 | *p = 7 3 | **q= 4 4 | 1 5 | 2 6 | 3 7 | 99 8 | 5 9 | 6 10 | 42 11 | 8 12 | 9 13 | *q=9 14 | -------------------------------------------------------------------------------- /29_outname/outname_test.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/29_outname/outname_test.o -------------------------------------------------------------------------------- /31_minesweeper/minesweeper: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/31_minesweeper/minesweeper -------------------------------------------------------------------------------- /34_put_together/outname.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/34_put_together/outname.o -------------------------------------------------------------------------------- /00_hello/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 02:54:27 UTC 2018 2 | Your file matched the expected output 3 | 4 | Overall Grade: PASSED 5 | -------------------------------------------------------------------------------- /01_apple/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 02:55:39 UTC 2018 2 | Your file matched the expected output 3 | 4 | Overall Grade: PASSED 5 | -------------------------------------------------------------------------------- /20_rot_matrix/Makefile: -------------------------------------------------------------------------------- 1 | rotate: rotate.c read-matrix.o 2 | gcc -o rotate -Wall -Werror -pedantic -std=gnu99 rotate.c read-matrix.o 3 | -------------------------------------------------------------------------------- /24_read_arr3/answer.txt: -------------------------------------------------------------------------------- 1 | x = 1 2 | *p = 7 3 | **q = 4 4 | 1 5 | 2 6 | 3 7 | 99 8 | 5 9 | 6 10 | 42 11 | 8 12 | 9 13 | *q = 9 14 | -------------------------------------------------------------------------------- /34_put_together/count_values: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/34_put_together/count_values -------------------------------------------------------------------------------- /26_tests_matrix_input/input5.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlienEdith/Introduction-to-Programming-in-C/HEAD/26_tests_matrix_input/input5.txt -------------------------------------------------------------------------------- /04_compile/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void){ 5 | printf("Hello World"); 6 | return EXIT_SUCCESS; 7 | } 8 | -------------------------------------------------------------------------------- /05_squares/3_5_8_2.txt: -------------------------------------------------------------------------------- 1 | ### 2 | # # 3 | ### 4 | 5 | 6 | 7 | 8 | 9 | ** 10 | ** 11 | -------------------------------------------------------------------------------- /29_outname/outname.h: -------------------------------------------------------------------------------- 1 | #ifndef __OUTNAME_H__ 2 | #define __OUTNAME_H__ 3 | 4 | char * computeOutputFileName(const char * inputName); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /34_put_together/list1b.txt: -------------------------------------------------------------------------------- 1 | kiwi 2 | lime 3 | pineapple 4 | pomegranate 5 | raisins 6 | apple 7 | blueberry 8 | carrot 9 | cherry 10 | dates 11 | -------------------------------------------------------------------------------- /34_put_together/list2c.txt: -------------------------------------------------------------------------------- 1 | Data 2 | Geordi LaForge 3 | Jean Luc Picard 4 | Tasha Yar 5 | Ro Laren 6 | Spock 7 | James T Kirk 8 | Katherine Janeway 9 | -------------------------------------------------------------------------------- /05_squares/ans_3_5_8_2.txt: -------------------------------------------------------------------------------- 1 | ### 2 | # # 3 | ### 4 | 5 | 6 | 7 | 8 | 9 | ** 10 | ** 11 | -------------------------------------------------------------------------------- /31_minesweeper/Makefile: -------------------------------------------------------------------------------- 1 | CCFLAGS=-Wall -pedantic -std=gnu99 -Werror -ggdb3 2 | minesweeper: minesweeper.c 3 | gcc -o minesweeper $(CCFLAGS) minesweeper.c 4 | -------------------------------------------------------------------------------- /34_put_together/list2b.txt: -------------------------------------------------------------------------------- 1 | Jean Luc Picard 2 | Q 3 | Geordi LaForge 4 | Some guy in a red shirt 5 | Reginald Barclay 6 | Beverly Crusher 7 | Data 8 | Worf 9 | -------------------------------------------------------------------------------- /05_squares/ans_9_2_3_4.txt: -------------------------------------------------------------------------------- 1 | ######### 2 | # # 3 | # # 4 | # **** # 5 | # * * # 6 | # * * # 7 | # **** # 8 | # # 9 | ######### 10 | -------------------------------------------------------------------------------- /05_squares/ans_5_2_4_6.txt: -------------------------------------------------------------------------------- 1 | ##### 2 | # # 3 | # # 4 | # # 5 | ##****** 6 | * * 7 | * * 8 | * * 9 | * * 10 | ****** 11 | -------------------------------------------------------------------------------- /21_read_rec1/README: -------------------------------------------------------------------------------- 1 | Execute the code in test.c (by hand). Write the resulting output in a file 2 | called "answer.txt". 3 | 4 | Check your work, and submit as usual. 5 | -------------------------------------------------------------------------------- /28_fix_vg_encr/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-ggdb3 -Wall -Werror -std=gnu99 -pedantic 2 | encrypt: encrypt.c 3 | gcc $(CFLAGS) -o encrypt encrypt.c 4 | clean: 5 | rm -f encrypt *~ 6 | -------------------------------------------------------------------------------- /34_put_together/list1a.txt: -------------------------------------------------------------------------------- 1 | apple 2 | avacado 3 | raspberry 4 | blueberry 5 | cherry 6 | eggplant 7 | grapes 8 | peach 9 | pineapple 10 | strawberry 11 | fig 12 | -------------------------------------------------------------------------------- /21_read_rec1/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 17:38:24 UTC 2018 2 | Your file matched the expected output 3 | Your output matched what we expected 4 | 5 | Overall Grade: A 6 | -------------------------------------------------------------------------------- /24_read_arr3/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 20:49:19 UTC 2018 2 | Your file matched the expected output 3 | Your output matched what we expected 4 | 5 | Overall Grade: A 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Introducation-to-Programming-in-C 2 | Couresra Specialization- Introduction to Programming in C 3 | 4 | https://www.coursera.org/specializations/c-programming 5 | -------------------------------------------------------------------------------- /26_tests_matrix_input/tests.txt: -------------------------------------------------------------------------------- 1 | 2 | input0.txt 3 | input1.txt 4 | input3.txt 5 | input2.txt 6 | input4.txt 7 | input5.txt 8 | fake.input 9 | empty input2.txt 10 | 11 | -------------------------------------------------------------------------------- /30_sort_lines/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-ggdb3 -Wall -Werror -std=gnu99 -pedantic 2 | sortLines: sortLines.c 3 | gcc $(CFLAGS) -o sortLines sortLines.c 4 | 5 | clean: 6 | rm -f sortLines *~ -------------------------------------------------------------------------------- /20_rot_matrix/my_ans.txt: -------------------------------------------------------------------------------- 1 | CH.....*a0 2 | oe....*.b1 3 | dl...*..c2 4 | il..*...d3 5 | no.*....e4 6 | gW*.....f5 7 | o......g6 8 | Fr......h7 9 | ul......i8 10 | nd......j9 11 | -------------------------------------------------------------------------------- /20_rot_matrix/sample.out: -------------------------------------------------------------------------------- 1 | CH.....*a0 2 | oe....*.b1 3 | dl...*..c2 4 | il..*...d3 5 | no.*....e4 6 | gW*.....f5 7 | o......g6 8 | Fr......h7 9 | ul......i8 10 | nd......j9 11 | -------------------------------------------------------------------------------- /20_rot_matrix/sample.txt: -------------------------------------------------------------------------------- 1 | 0123456789 2 | abcdefghij 3 | *......... 4 | .*........ 5 | ..*....... 6 | ...*...... 7 | ....*..... 8 | .....*.... 9 | HelloWorld 10 | Coding Fun 11 | -------------------------------------------------------------------------------- /27_matrix_input/sample.out: -------------------------------------------------------------------------------- 1 | CH.....*a0 2 | oe....*.b1 3 | dl...*..c2 4 | il..*...d3 5 | no.*....e4 6 | gW*.....f5 7 | o......g6 8 | Fr......h7 9 | ul......i8 10 | nd......j9 11 | -------------------------------------------------------------------------------- /27_matrix_input/sample.txt: -------------------------------------------------------------------------------- 1 | 0123456789 2 | abcdefghij 3 | *......... 4 | .*........ 5 | ..*....... 6 | ...*...... 7 | ....*..... 8 | .....*.... 9 | HelloWorld 10 | Coding Fun 11 | -------------------------------------------------------------------------------- /26_tests_matrix_input/input0.txt: -------------------------------------------------------------------------------- 1 | 1234567890 2 | sfdsfddgfg 3 | afsafsfdsf 4 | afsfdsfdsf 5 | dgdgfgfgfg 6 | adsadsdsfg 7 | afsfdfdhjk 8 | sfdsfdbvbd 9 | ashfshflks 10 | sajlasjfls 11 | -------------------------------------------------------------------------------- /26_tests_matrix_input/input1.txt: -------------------------------------------------------------------------------- 1 | 1234567890 2 | skfdhsfkdf 3 | amdalsmldf 4 | ajksfkfdkj 5 | asakflskfl 6 | asdlfksakl 7 | jslkjsldjd 8 | jlfjslfjd 9 | sflsjflddg 10 | alkslfklff 11 | -------------------------------------------------------------------------------- /26_tests_matrix_input/input6.txt: -------------------------------------------------------------------------------- 1 | 1234567890 2 | /n/n/n/n/n 3 | %fdsfddgfg 4 | afsafsjhgh 5 | dgdgfgfgfg 6 | addjfkga01 7 | fdsfdbvbd 8 | ashfshflks 9 | sajlasjfls 10 | gjgjjhjhjj 11 | -------------------------------------------------------------------------------- /c4prj3_finish/provided-tests/test16.txt: -------------------------------------------------------------------------------- 1 | 3h ?0 Kc ?1 Qh ?2 2h 2 | Ac ?1 Jd ?2 3d ?3 5c 3 | Qc ?2 Qd ?3 3h ?4 2s 4 | Js ?3 0s ?4 9c ?5 6d 5 | 7h ?4 3h ?5 2h ?0 Ah 6 | Kd ?5 Qh ?0 Js ?1 As 7 | -------------------------------------------------------------------------------- /24_read_arr3/README: -------------------------------------------------------------------------------- 1 | Execute the code in test.c by hand, and place the resulting 2 | output in a file called "answer.txt". 3 | As always, compile and run test.c to check your work, and submit. 4 | -------------------------------------------------------------------------------- /26_tests_matrix_input/input4.txt: -------------------------------------------------------------------------------- 1 | a1234567890 2 | sfdsfdfffg 3 | sfdsfddgfg 4 | aafsafs""k 5 | dgdgfgfgfg 6 | adhjdsdsfg 7 | afsfdfdhjk 8 | sfdsfdbvbd 9 | ashfshflks 10 | sajlasjfls 11 | -------------------------------------------------------------------------------- /09_testing2/tests.txt: -------------------------------------------------------------------------------- 1 | 2 | aaaaa 3 | aaaaa 4 | aaaaaa aaaaa 5 | aaaaa aaaaaa 6 | aaaa aaaaa 7 | aaaaa aaaa 8 | assdf sfsfg sf 9 | aaabb bbaaa 10 | 0jsja jao-1 11 | 00f00 11111 12 | 13 | -------------------------------------------------------------------------------- /04_compile/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 03:10:00 UTC 2018 2 | Compiling your code 3 | Checking if your program prints "Hello World" 4 | Your file matched the expected output 5 | 6 | Overall Grade: PASSED 7 | -------------------------------------------------------------------------------- /26_tests_matrix_input/input3.txt: -------------------------------------------------------------------------------- 1 | 1234567890 2 | sfdsfdfffg 3 | sfdsfddgfg 4 | afsafsfdsf 5 | afsfdsfdsf 6 | dgdgfgfgfg 7 | adsadsdsfg 8 | afsfdfdhjk 9 | sfdsfdbvbd 10 | ashfshflks 11 | sajlasjfls 12 | -------------------------------------------------------------------------------- /c4prj3_finish/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-Wall -Werror -ggdb3 -std=gnu99 -pedantic $(OTHERFLAGS) 3 | poker: cards.o deck.o eval.o future.o input.o main.o 4 | gcc -o $@ $(CFLAGS) $^ 5 | clean: 6 | rm -rf *.o poker *~ 7 | -------------------------------------------------------------------------------- /18_reverse_str/ans.txt: -------------------------------------------------------------------------------- 1 | 2 | 321 3 | dcba 4 | 7.32524 etadratS ,gol s'niatpaC 5 | .ayotnoM oginI si eman ym ,olleH 6 | !yadyna namgniw ym eb nac uoY 7 | !worromot on eb yam erehT !secrof ruoy fo rewop lluf eht hsaelnU !sidneleS rotucexE 8 | -------------------------------------------------------------------------------- /18_reverse_str/reverse_ans.txt: -------------------------------------------------------------------------------- 1 | 2 | 321 3 | dcba 4 | 7.32524 etadratS ,gol s'niatpaC 5 | .ayotnoM oginI si eman ym ,olleH 6 | !yadyna namgniw ym eb nac uoY 7 | !worromot on eb yam erehT !secrof ruoy fo rewop lluf eht hsaelnU !sidneleS rotucexE 8 | -------------------------------------------------------------------------------- /32_kvs/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-Wall -Werror -std=gnu99 -pedantic -ggdb3 2 | OBJS=kv_test.o kv.o 3 | PROGRAM=kv_test 4 | 5 | $(PROGRAM): $(OBJS) 6 | gcc $(CFLAGS) -o $@ $(OBJS) 7 | 8 | %.o: %.c kv.h 9 | gcc -c $(CFLAGS) $< 10 | 11 | clean: 12 | rm -f $(OBJS) $(PROGRAM) *~ -------------------------------------------------------------------------------- /13_read_arr1/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 05:59:56 UTC 2018 2 | Attempting to compile test.c 3 | gcc -o test -Wall -Werror --pedantic -std=gnu99 test.c 4 | compiled 5 | Your file matched the expected output 6 | Your output matched what we expected 7 | 8 | Overall Grade: A 9 | -------------------------------------------------------------------------------- /17_read_arr2/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 07:01:00 UTC 2018 2 | Attempting to compile test.c 3 | gcc -o test -Wall -Werror -pedantic -std=gnu99 test.c 4 | compiled 5 | Your file matched the expected output 6 | Your output matched what we expected 7 | 8 | Overall Grade: A 9 | -------------------------------------------------------------------------------- /23_power_rec/power.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | unsigned power(unsigned x, unsigned y){ 5 | unsigned res = 1; 6 | if(y==0) return 1; 7 | if(y==1) return x; 8 | res = x * power(x, y-1); 9 | return res; 10 | } 11 | -------------------------------------------------------------------------------- /11_read_ptr1/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 05:39:10 UTC 2018 2 | Attempting to compile test.c 3 | gcc -o test -Wall -Werror -pedantic -std=gnu99 test.c 4 | compiled 5 | Your file matched the expected output 6 | Your output matched what we expected 7 | 8 | Overall Grade: PASSED 9 | -------------------------------------------------------------------------------- /12_read_ptr2/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 05:54:26 UTC 2018 2 | Attempting to compile test.c 3 | gcc -o test -Wall -Werror --pedantic -std=gnu99 test.c 4 | compiled 5 | Your file matched the expected output 6 | Your output matched what we expected 7 | 8 | Overall Grade: PASSED 9 | -------------------------------------------------------------------------------- /33_counts/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-Wall -Werror -std=gnu99 -pedantic -ggdb3 2 | OBJS=counts.o counts_test.o 3 | PROGRAM=counts_test 4 | 5 | $(PROGRAM): $(OBJS) 6 | gcc $(CFLAGS) -o $@ $(OBJS) 7 | 8 | %.o: %.c counts.h 9 | gcc -c $(CFLAGS) $< 10 | 11 | clean: 12 | rm -f $(OBJS) $(PROGRAM) *~ -------------------------------------------------------------------------------- /29_outname/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-Wall -Werror -std=gnu99 -pedantic -ggdb3 2 | OBJS=outname.o outname_test.o 3 | PROGRAM=outname_test 4 | 5 | $(PROGRAM): $(OBJS) 6 | gcc $(CFLAGS) -o $@ $(OBJS) 7 | 8 | %.o: %.c outname.h 9 | gcc -c $(CFLAGS) $< 10 | 11 | clean: 12 | rm -f $(OBJS) $(PROGRAM) *~ -------------------------------------------------------------------------------- /11_read_ptr1/README: -------------------------------------------------------------------------------- 1 | 1. Execute the code in "test.c" by hand, and write the output 2 | into a file called "answer.txt" 3 | 4 | 2. Create a Makefile to compile test.c into a program called "test" 5 | 6 | 3. Run test and use its output to check your work. 7 | 8 | 4. Submit your Makefile and your answer.txt file 9 | 10 | 11 | -------------------------------------------------------------------------------- /12_read_ptr2/README: -------------------------------------------------------------------------------- 1 | 1. Execute the code in "test.c" by hand, and write the output 2 | into a file called "answer.txt" 3 | 4 | 2. Create a Makefile to compile test.c into a program called "test" 5 | 6 | 3. Run test and use its output to check your work. 7 | 8 | 4. Submit your Makefile and your answer.txt file 9 | 10 | 11 | -------------------------------------------------------------------------------- /13_read_arr1/README: -------------------------------------------------------------------------------- 1 | 2 | 1. Execute the code in "test.c" by hand, and write the output 3 | into a file called "answer.txt" 4 | 5 | 2. Create a Makefile to compile test.c into a program called "test" 6 | 7 | 3. Run test and use its output to check your work. 8 | 9 | 4. Submit your Makefile and your answer.txt file. 10 | 11 | -------------------------------------------------------------------------------- /34_put_together/kvs2.txt: -------------------------------------------------------------------------------- 1 | Jean Luc Picard=Captain 2 | Will Riker=Commander 3 | Beverly Crusher=Commander 4 | Data=Lt. Commander 5 | Geordi LaForge=Lt. Commander 6 | Worf=Lt. Commander 7 | Deanna Troi=Commander 8 | Tasha Yar=Lieutenant 9 | Wesley Crusher=Ensign 10 | Ro Laren=Ensign 11 | Reginald Barclay=Lieutenant 12 | Guinan=Bartender 13 | -------------------------------------------------------------------------------- /c3prj1_deck/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-ggdb3 -Wall -Werror -pedantic -std=gnu99 2 | GIVEN_OBJS=deck-c4.o eval-c4.o future.o input.o main.o 3 | MY_OBJS=cards.o deck.o eval.o 4 | 5 | test-deck: deck.o test-deck.o deck-c4.o cards.o 6 | gcc -o test-deck -ggdb3 deck.o test-deck.o deck-c4.o cards.o 7 | clean: 8 | rm test poker cards.o my-test-main.o *~ 9 | -------------------------------------------------------------------------------- /c3prj2_eval/eval.h: -------------------------------------------------------------------------------- 1 | #ifndef EVAL_H 2 | #define EVAL_H 3 | #include "deck.h" 4 | struct hand_eval_tag { 5 | hand_ranking_t ranking; 6 | card_t *cards[5]; 7 | }; 8 | typedef struct hand_eval_tag hand_eval_t; 9 | 10 | hand_eval_t evaluate_hand(deck_t * hand) ; 11 | int compare_hands(deck_t * hand1, deck_t * hand2) ; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /c2prj1_cards/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-ggdb3 -Wall -Werror -pedantic -std=gnu99 2 | GIVEN_OBJS=deck.o eval.o future.o input.o main.o eval-c4.o deck-c4.o 3 | 4 | test: cards.o my-test-main.o 5 | gcc -o test -ggdb3 cards.o my-test-main.o 6 | poker: $(GIVEN_OBJS) cards.o 7 | gcc -o poker -ggdb3 cards.o $(GIVEN_OBJS) 8 | clean: 9 | rm test poker cards.o my-test-main.o *~ 10 | -------------------------------------------------------------------------------- /20_rot_matrix/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 17:33:31 UTC 2018 2 | Attempting to compile rotate.c 3 | Running testcase 1 4 | Your file matched the expected output 5 | testcase1 passed 6 | Running testcase 1 7 | Your file matched the expected output 8 | testcase1 passed 9 | Running testcase 1 10 | Your file matched the expected output 11 | testcase1 passed 12 | 13 | Overall Grade: A 14 | -------------------------------------------------------------------------------- /c4prj2_input/future.h: -------------------------------------------------------------------------------- 1 | #ifndef FUTURE_H 2 | #define FUTURE_H 3 | #include "deck.h" 4 | 5 | 6 | struct future_cards_tag { 7 | deck_t * decks; 8 | size_t n_decks; 9 | }; 10 | typedef struct future_cards_tag future_cards_t; 11 | void add_future_card(future_cards_t * fc, size_t index, card_t * ptr) ; 12 | void future_cards_from_deck(deck_t * deck, future_cards_t * fc); 13 | 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /34_put_together/kvs1.txt: -------------------------------------------------------------------------------- 1 | apple=red 2 | apricot=yellow 3 | avacado=green 4 | banana=yellow 5 | blueberry=blue 6 | carrot=orange 7 | cherry=red 8 | cranberry=red 9 | dates=brown 10 | eggplant=purple 11 | grapefruit=pink 12 | grapes=purple 13 | kiwi=green 14 | lime=green 15 | orange=orange 16 | peach=yellow 17 | pineapple=yellow 18 | plums=purple 19 | pomegranate=red 20 | strawberry=red 21 | tomato=red 22 | -------------------------------------------------------------------------------- /01_apple/README: -------------------------------------------------------------------------------- 1 | Ok, now you've been walked through editing, saving, 2 | and submitting an assignment. For this assignment, we're just going 3 | to have you practice that on your own before 4 | we move on to things involving writing code. 5 | 6 | - Create a file called "fruit.txt" 7 | - Write one line, containing the text 8 | apple 9 | into that file 10 | - Save the file and submit the assignment for grading 11 | -------------------------------------------------------------------------------- /c4prj2_input/input.h: -------------------------------------------------------------------------------- 1 | #ifndef INPUT_H 2 | #define INPUT_H 3 | #include 4 | #include "deck.h" 5 | #include "future.h" 6 | 7 | size_t strToInt(char * str); 8 | void lineToStr(char *line); 9 | int getLastIndex(const char * str, int fstIdx); 10 | deck_t * hand_from_string(const char * str, future_cards_t * fc); 11 | deck_t ** read_input(FILE * f, size_t * n_hands, future_cards_t * fc); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /17_read_arr2/README: -------------------------------------------------------------------------------- 1 | 1. Execute the code in "test.c" by hand, and write the output 2 | into a file called "answer.txt" 3 | 4 | Hint: you may need to consult the man pages for functions 5 | that you are not familiar with. 6 | 7 | 2. Create a Makefile to compile test.c into a program called "test" 8 | 9 | 3. Run test and use its output to check your work. 10 | 11 | 4. Submit your Makefile and answer.txt 12 | 13 | -------------------------------------------------------------------------------- /06_rect/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 03:39:06 UTC 2018 2 | Attempting to compile rectangle.c 3 | Tring to run rectangle 4 | Your file matched the expected output 5 | removing your main() and replacing it with out own to run more tests... 6 | ################################################# 7 | testcase1: 8 | testcase1 passed 9 | ################################################# 10 | testcase2: 11 | testcase2 passed 12 | 13 | Overall Grade: A 14 | -------------------------------------------------------------------------------- /25_break_encr/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 21:08:54 UTC 2018 2 | Attempting to compile breaker.c 3 | make: 'breaker' is up to date. 4 | testcase1 passed 5 | ################################################# 6 | testcase2: 7 | testcase2 passed 8 | ################################################# 9 | testcase3: 10 | testcase3 passed 11 | ################################################# 12 | testcase4: 13 | testcase4 passed 14 | 15 | Overall Grade: A 16 | -------------------------------------------------------------------------------- /34_put_together/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-Wall -Werror -std=gnu99 -pedantic -ggdb3 2 | SRCS=$(wildcard *.c) 3 | OBJS=$(patsubst %.c, %.o, $(SRCS)) 4 | PROGRAM=count_values 5 | 6 | $(PROGRAM): $(OBJS) 7 | gcc $(CFLAGS) -o $@ $(OBJS) 8 | 9 | %.o: %.c 10 | gcc -c $(CFLAGS) $< 11 | 12 | clean: 13 | rm -f $(OBJS) $(PROGRAM) *~ 14 | 15 | counts.o: counts.h 16 | outname.o: outname.h 17 | kv.o: kv.h 18 | main.o: kv.h 19 | main.o: outname.h 20 | main.o: counts.h 21 | -------------------------------------------------------------------------------- /20_rot_matrix/rotate.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void rotate(char matrix[10][10]){ 5 | int range = 9; 6 | for(int i=0; i<5; i++){ 7 | for(int j=i; j<9-i; j++){ 8 | char temp = matrix[i][j]; 9 | matrix[i][j] = matrix[range-j][i]; 10 | matrix[range-j][i] = matrix[range-i][range-j]; 11 | matrix[range-i][range-j] = matrix[j][range-i]; 12 | matrix[j][range-i] = temp; 13 | } 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /13_read_arr1/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main(void) { 6 | int anArray[] = {5,16,33,99}; 7 | int * p = anArray; 8 | printf("*p = %d\n", *p); 9 | p++; 10 | printf("Now *p = %d\n", *p); 11 | int * q = &anArray[3]; 12 | int ** x = &q; 13 | **x = 12; 14 | *x = p; 15 | **x = 42; 16 | q[1] = 9; 17 | for (int i =0; i < 4; i++){ 18 | printf("anArray[%d] = %d\n",i, anArray[i]); 19 | } 20 | return EXIT_SUCCESS; 21 | } 22 | -------------------------------------------------------------------------------- /29_outname/outname_test.c: -------------------------------------------------------------------------------- 1 | #include "outname.h" 2 | #include 3 | #include 4 | 5 | 6 | #define NUM_TESTS 3 7 | int main(void) { 8 | char * testNames[NUM_TESTS] = {"input.txt", 9 | "anotherTestFileName.txt", 10 | "somethingelse"}; 11 | 12 | for (int i = 0; i < NUM_TESTS; i++) { 13 | char * outName = computeOutputFileName(testNames[i]); 14 | printf("'%s' => '%s'\n", testNames[i], outName); 15 | free(outName); 16 | } 17 | return EXIT_SUCCESS; 18 | } 19 | -------------------------------------------------------------------------------- /c3prj2_eval/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-ggdb3 -Wall -Werror -pedantic -std=gnu99 2 | GIVEN_OBJS=deck-c4.o eval-c4.o future.o input.o main.o 3 | MY_OBJS=cards.o deck.o eval.o 4 | 5 | test-eval: deck.o eval.o eval-c4.o test-eval.o deck-c4.o cards.o input.o future.o 6 | gcc -o test-eval -ggdb3 deck.o deck-c4.o eval-c4.o eval.o test-eval.o cards.o input.o future.o 7 | poker: $(GIVEN_OBJS) $(MY_OBJS) 8 | gcc -o poker -ggdb3 $(MY_OBJS) $(GIVEN_OBJS) 9 | clean: 10 | rm test poker cards.o my-test-main.o *~ 11 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Welcome to the Practice Programming Environment. 2 | 3 | This is where 4 | This is your directory for the assignments in this 5 | specialization. To do the first assignment: 6 | 7 | cd 00_hello 8 | 9 | There, you will find a README with instructions. 10 | Once you do them and pass that assignment, 11 | the Practice Programming Environment will 12 | automatically give you the next assignment. 13 | You should then continue readings and videos 14 | in Coursera until you are ready for that assignment. 15 | -------------------------------------------------------------------------------- /c3prj1_deck/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 18:29:14 UTC 2018 2 | Compiling deck.c 3 | Compiling cards.c 4 | Linking cards.o deck.o deck-c4.o and the grader's .o file 5 | Checking the output of all the functions other than shuffle 6 | Your file matched the expected output 7 | - Those functions seem to work! 8 | Checking your shuffle results with a 6 card hand... 9 | Least common hand: 0.131800% 10 | Most common hand: 0.146250% 11 | Perfectly even is: 0.138888% 12 | Excellent! 13 | 14 | Overall Grade: A 15 | -------------------------------------------------------------------------------- /21_read_rec1/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void printDigits(int x) { 5 | if (x == 0) { 6 | printf("0"); 7 | } 8 | else if (x < 0) { 9 | printf("-"); 10 | printDigits(-x); 11 | } 12 | else { 13 | int a = x/10; 14 | int b = x %10; 15 | printf("a=%d, b=%d\n",a,b); 16 | if (a != 0) { 17 | printDigits(a); 18 | } 19 | printf("%d",b); 20 | } 21 | } 22 | 23 | 24 | int main(void) { 25 | printDigits(297); 26 | printf("\n"); 27 | return EXIT_SUCCESS; 28 | } 29 | -------------------------------------------------------------------------------- /32_kvs/kv_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "kv.h" 5 | 6 | #define NUM_LOOKUPS 5 7 | int main(void) { 8 | kvarray_t * array = readKVs("test.txt"); 9 | printf("Printing all keys\n\n"); 10 | printKVs(array); 11 | char *tests[NUM_LOOKUPS] = {"banana", "grapes", "cantaloupe", "lettuce", "orange"}; 12 | for (int i = 0; i < NUM_LOOKUPS; i++) { 13 | printf("lookupValue('%s')=%s\n", tests[i], lookupValue(array,tests[i])); 14 | } 15 | freeKVs(array); 16 | return EXIT_SUCCESS; 17 | } 18 | -------------------------------------------------------------------------------- /11_read_ptr1/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void g(int x, int * y) { 5 | printf("In g, x = %d, *y = %d\n", x, *y); 6 | x++; 7 | *y = *y - x; 8 | y = &x; 9 | } 10 | 11 | void f(int * a, int b) { 12 | printf("In f, *a = %d, b = %d\n", *a, b); 13 | *a += b; 14 | b *= 2; 15 | g(*a, &b); 16 | printf("Back in f, *a = %d, b = %d\n", *a, b); 17 | } 18 | 19 | 20 | int main(void) { 21 | int x = 3; 22 | int y = 4; 23 | f(&x, y); 24 | printf("In main: x = %d, y = %d\n", x, y); 25 | return EXIT_SUCCESS; 26 | } 27 | -------------------------------------------------------------------------------- /33_counts/counts_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "counts.h" 5 | 6 | #define NUM_TESTS 12 7 | int main(void) { 8 | char * testData[NUM_TESTS] = {"apple", "banana", NULL,"apple", 9 | "frog","sword","bear",NULL, 10 | "frog","apple", "zebra", "knight"}; 11 | counts_t * testCounts= createCounts(); 12 | for(int i =0; i < NUM_TESTS; i++) { 13 | addCount(testCounts,testData[i]); 14 | } 15 | printCounts(testCounts, stdout); 16 | freeCounts(testCounts); 17 | return EXIT_SUCCESS; 18 | } 19 | -------------------------------------------------------------------------------- /16_subseq/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 06:39:14 UTC 2018 2 | Attempting to compile maxSeq.c 3 | Linking your object file with our test main 4 | ################################################# 5 | testcase2: 6 | array size:0 was Correct 7 | ################################################# 8 | testcase3: 9 | array size:1 was Correct 10 | ################################################# 11 | testcase4: 12 | array size:100 was Correct 13 | ################################################# 14 | testcase5: 15 | array size:5000 was Correct 16 | 17 | Overall Grade: A 18 | -------------------------------------------------------------------------------- /32_kvs/kv.h: -------------------------------------------------------------------------------- 1 | #ifndef __KV_H__ 2 | #define __KV_H__ 3 | 4 | 5 | struct _kvpair_t { 6 | //DEFINE ME! 7 | char * key; 8 | char * value; 9 | }; 10 | typedef struct _kvpair_t kvpair_t; 11 | 12 | struct _kvarray_t { 13 | //DEFINE ME! 14 | kvpair_t ** array; 15 | size_t sz; 16 | 17 | }; 18 | typedef struct _kvarray_t kvarray_t; 19 | 20 | 21 | kvarray_t * readKVs(const char * fname); 22 | 23 | void freeKVs(kvarray_t * pairs); 24 | 25 | void printKVs(kvarray_t * pairs); 26 | 27 | char * lookupValue(kvarray_t * pairs, const char * key); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /33_counts/counts.h: -------------------------------------------------------------------------------- 1 | #ifndef __COUNTS_H__ 2 | #define __COUNTS_H__ 3 | struct _one_count_t { 4 | //DEFINE ME 5 | char * str; 6 | unsigned counts; 7 | }; 8 | typedef struct _one_count_t one_count_t; 9 | 10 | struct _counts_t { 11 | //DEFINE ME 12 | one_count_t ** array; 13 | size_t sz; 14 | size_t unknowSz; 15 | }; 16 | typedef struct _counts_t counts_t; 17 | 18 | counts_t * createCounts(void); 19 | void addCount(counts_t * c, const char * name); 20 | void printCounts(counts_t * c, FILE * outFile); 21 | 22 | void freeCounts(counts_t * c); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /22_tests_power/test-power.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | unsigned power(unsigned x, unsigned y); 4 | 5 | int main(void){ 6 | 7 | if(power(2,2) != 4){ 8 | return EXIT_FAILURE; 9 | } 10 | 11 | if(power(0,0) != 1){ 12 | return EXIT_FAILURE; 13 | } 14 | 15 | if(power(0,1) != 0){ 16 | return EXIT_FAILURE; 17 | } 18 | 19 | if(power(-2,1) != (-2)){ 20 | return EXIT_FAILURE; 21 | } 22 | 23 | if(power(-2,2) != 4){ 24 | return EXIT_FAILURE; 25 | } 26 | 27 | return EXIT_SUCCESS; 28 | } 29 | -------------------------------------------------------------------------------- /16_subseq/maxSeq.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | size_t maxSeq(int * array, size_t n){ 6 | if(n==0) return 0; 7 | int maxSeqLen = 1; 8 | int curSeqLen = 1; 9 | int * curValp = array; 10 | int * lastValp = array; 11 | for(int i=1; i *lastValp){ 15 | curSeqLen++; 16 | if(curSeqLen > maxSeqLen){ 17 | maxSeqLen = curSeqLen; 18 | } 19 | }else{ 20 | curSeqLen = 1; 21 | } 22 | } 23 | return maxSeqLen; 24 | } 25 | -------------------------------------------------------------------------------- /02_code1/code1.c: -------------------------------------------------------------------------------- 1 | int max (int num1, int num2) { 2 | //check if num1 is greater than num2 3 | //if so, your answer is num1 4 | //otherwise, your answer is num2 5 | return (num1>num2)? num1 : num2; 6 | } 7 | 8 | int main(void) { 9 | printf("max(42, -69) is %d\n", max(42, -69)); 10 | printf("max(33, 0) is %d\n", max(33, 0)); 11 | printf("max(0x123456, 123456) is %d\n", max(0x123456, 123456)); 12 | //compute the max of 0x451215AF and 0x913591AF and print it out as a decimal number 13 | printf("max(0x451215AF,0x913591AF) is %d\n",max(0x451215AF,0x913591AF)); 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /14_array_max/README: -------------------------------------------------------------------------------- 1 | 1. Open the provided arrayMax.c file and write 2 | the function: 3 | int * arrayMax(int * array, int n); 4 | which returns a pointer to the largest element 5 | in the array passed in (whose length is n). 6 | If the array has no elements (n is 0), this function 7 | should return NULL. 8 | 9 | 2. Compile and test your code. 10 | We have provided a main function which will print test cases 11 | and your function's answer for them. You should get 12 | 99, -3, 425, NULL, and NULL for the 5 test provided. 13 | 14 | 3. Submit your code. 15 | 16 | 17 | -------------------------------------------------------------------------------- /08_testing/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 04:41:53 UTC 2018 2 | ################################################# 3 | test input.1: 4 | Your file matched the expected output 5 | input.1 passed 6 | ################################################# 7 | test input.2: 8 | Your file matched the expected output 9 | input.2 passed 10 | ################################################# 11 | test input.3: 12 | Your file matched the expected output 13 | input.3 passed 14 | ################################################# 15 | test input.4: 16 | Your file matched the expected output 17 | input.4 passed 18 | 19 | Overall Grade: A 20 | -------------------------------------------------------------------------------- /19_bits_arr/ans.txt: -------------------------------------------------------------------------------- 1 | 1 ( 1) => 00000000000000000000000000000001 2 | 2 ( 2) => 00000000000000000000000000000010 3 | 3 ( 3) => 00000000000000000000000000000011 4 | 4 ( 4) => 00000000000000000000000000000100 5 | 5 ( 5) => 00000000000000000000000000000101 6 | 15 ( F) => 00000000000000000000000000001111 7 | 109 ( 6D) => 00000000000000000000000001101101 8 | 123456789 ( 75BCD15) => 00000111010110111100110100010101 9 | 987654321 (3ADE68B1) => 00111010110111100110100010110001 10 | Invalid call to numToBits! nBits is 223, nNums is 7 11 | -------------------------------------------------------------------------------- /04_compile/README: -------------------------------------------------------------------------------- 1 | For this assignment, you will be practicing writing, compiling, and 2 | running code. You should write a C file, called hello.c, with a main 3 | function that uses the printf function to print the message 4 | 5 | Hello World 6 | 7 | [be sure to include a newline!] 8 | 9 | Your program should return EXIT_SUCCESS to indicate that it was successful 10 | (the return value of main indicates success [0] or failure [anything else]). 11 | 12 | Don't forget to include stdio.h (for printf) and stdlib.h (for 13 | EXIT_SUCCESS). 14 | 15 | When you are done, compile your code and run it. 16 | The submit it for grading. 17 | -------------------------------------------------------------------------------- /19_bits_arr/bits_ans.txt: -------------------------------------------------------------------------------- 1 | 1 ( 1) => 00000000000000000000000000000001 2 | 2 ( 2) => 00000000000000000000000000000010 3 | 3 ( 3) => 00000000000000000000000000000011 4 | 4 ( 4) => 00000000000000000000000000000100 5 | 5 ( 5) => 00000000000000000000000000000101 6 | 15 ( F) => 00000000000000000000000000001111 7 | 109 ( 6D) => 00000000000000000000000001101101 8 | 123456789 ( 75BCD15) => 00000111010110111100110100010101 9 | 987654321 (3ADE68B1) => 00111010110111100110100010110001 10 | Invalid call to numToBits! nBits is 223, nNums is 7 11 | -------------------------------------------------------------------------------- /29_outname/outname.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "outname.h" 5 | 6 | char * computeOutputFileName(const char * inputName) { 7 | //WRITE ME 8 | int len = strlen(inputName); 9 | char * OutNameptr = malloc((len+8) * sizeof(*OutNameptr)); 10 | char * ptr = OutNameptr; 11 | 12 | while(*inputName != '\0'){ 13 | *ptr = *inputName; 14 | ptr++; 15 | inputName++; 16 | } 17 | 18 | char * suffix = ".counts"; 19 | while(*suffix != '\0'){ 20 | *ptr = *suffix; 21 | ptr++; 22 | suffix++; 23 | } 24 | *ptr = '\0'; 25 | 26 | return OutNameptr; 27 | } 28 | -------------------------------------------------------------------------------- /32_kvs/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Mon Oct 15 03:53:30 UTC 2018 2 | Attempting to compile: 3 | ################################################# 4 | testcase1: 5 | Your output is correct 6 | - Valgrind was clean (no errors, no memory leaks) 7 | valgrind was clean 8 | ################################################# 9 | testcase2: 10 | Your output is correct 11 | - Valgrind was clean (no errors, no memory leaks) 12 | valgrind was clean 13 | ################################################# 14 | testcase3: 15 | Your output is correct 16 | - Valgrind was clean (no errors, no memory leaks) 17 | valgrind was clean 18 | 19 | Overall Grade: A 20 | -------------------------------------------------------------------------------- /29_outname/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 23:38:38 UTC 2018 2 | Attempting to compile: 3 | ################################################# 4 | testcase1: 5 | Your output is correct 6 | - Valgrind was clean (no errors, no memory leaks) 7 | valgrind was clean 8 | ################################################# 9 | testcase2: 10 | Your output is correct 11 | - Valgrind was clean (no errors, no memory leaks) 12 | valgrind was clean 13 | ################################################# 14 | testcase3: 15 | Your output is correct 16 | - Valgrind was clean (no errors, no memory leaks) 17 | valgrind was clean 18 | 19 | Overall Grade: A 20 | -------------------------------------------------------------------------------- /33_counts/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Mon Oct 15 04:27:47 UTC 2018 2 | Attempting to compile: 3 | ################################################# 4 | testcase1: 5 | Your output is correct 6 | - Valgrind was clean (no errors, no memory leaks) 7 | valgrind was clean 8 | ################################################# 9 | testcase2: 10 | Your output is correct 11 | - Valgrind was clean (no errors, no memory leaks) 12 | valgrind was clean 13 | ################################################# 14 | testcase3: 15 | Your output is correct 16 | - Valgrind was clean (no errors, no memory leaks) 17 | valgrind was clean 18 | 19 | Overall Grade: A 20 | -------------------------------------------------------------------------------- /12_read_ptr2/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int f(int ** r, int ** s) { 5 | int temp = ** r; 6 | int temp2 = **s; 7 | int * z = *r; 8 | *r = *s; 9 | *s = z; 10 | printf("**r = %d\n",**r); 11 | printf("**s = %d\n",**s); 12 | *z += 3; 13 | **s -= 8; 14 | **r -= 19; 15 | return temp + temp2; 16 | } 17 | 18 | int main(void) { 19 | int a = 80; 20 | int b = 12; 21 | int * p = &a; 22 | int * q = &b; 23 | int x = f(&p, &q); 24 | printf("x = %d\n", x); 25 | printf("*p = %d\n", *p); 26 | printf("*q = %d\n", *q); 27 | printf("a = %d\n", a); 28 | printf("b = %d\n", b); 29 | return EXIT_SUCCESS; 30 | } 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /19_bits_arr/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 16:00:54 UTC 2018 2 | Attempting to compile numToBits.c 3 | Your file matched the expected output 4 | Your output matched what we expected 5 | Removing your main() and replacing it with our own to run more tests... 6 | ################################################# 7 | testcase2: 8 | array size:0 was Correct 9 | ################################################# 10 | testcase3: 11 | array size:1 was Correct 12 | ################################################# 13 | testcase4: 14 | array size:100 was Correct 15 | ################################################# 16 | testcase5: 17 | array size:5000 was Correct 18 | 19 | Overall Grade: A 20 | -------------------------------------------------------------------------------- /c3prj1_deck/deck.h: -------------------------------------------------------------------------------- 1 | #ifndef DECK_H 2 | #define DECK_H 3 | #include 4 | #include "cards.h" 5 | struct deck_tag { 6 | card_t ** cards; 7 | size_t n_cards; 8 | }; 9 | typedef struct deck_tag deck_t; 10 | 11 | void print_hand(deck_t * hand); 12 | int deck_contains(deck_t * d, card_t c) ; 13 | void shuffle(deck_t * d); 14 | void assert_full_deck(deck_t * d) ; 15 | //The below functions will be done in course 4. 16 | deck_t * make_deck_exclude(deck_t * excluded_cards); 17 | void add_card_to(deck_t * deck, card_t c); 18 | card_t * add_empty_card(deck_t * deck); 19 | void free_deck(deck_t * deck) ; 20 | deck_t * build_remaining_deck(deck_t ** hands, size_t n_hands) ; 21 | #endif 22 | -------------------------------------------------------------------------------- /18_reverse_str/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 07:17:10 UTC 2018 2 | Attempting to compile reverse.c 3 | Your file matched the expected output 4 | Your output matched what we expected 5 | Removing your main() and replacing it with our own to run more tests... 6 | ################################################# 7 | testcase2: 8 | nullptr################################################# 9 | testcase3: 10 | Your file matched the expected output 11 | ################################################# 12 | testcase4: 13 | Your file matched the expected output 14 | ################################################# 15 | testcase5: 16 | Your file matched the expected output 17 | 18 | Overall Grade: A 19 | -------------------------------------------------------------------------------- /18_reverse_str/README: -------------------------------------------------------------------------------- 1 | For this problem, you will write the function 2 | 3 | void reverse(char * str) 4 | 5 | in the provided reverse.c file. This function should reverse the string 6 | passed into it (that is, if given "abc", it should change the contents 7 | of that string to read "cba"). Note that this function's return type 8 | is "void"---it modifies the string passed into it in place. 9 | 10 | We have provided a main function which you can use to test your 11 | reverse function (do you recognize the quotations?). The correct 12 | output for your program can be found in reverse_ans.txt, so you can 13 | diff your program's output against it. 14 | 15 | Submit your reverse.c file for grading. 16 | -------------------------------------------------------------------------------- /24_read_arr3/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int* aFunction(int x, int *p, int ** q) { 5 | printf("x = %d\n", x); 6 | printf("*p = %d\n", *p); 7 | printf("**q= %d\n", **q); 8 | *p = 42; 9 | **q = 99; 10 | *q = &p[1]; 11 | return &p[2]; 12 | } 13 | 14 | int main (void) { 15 | int anArray[3][3] = { {1,2,3}, 16 | {4,5,6}, 17 | {7,8,9} }; 18 | 19 | int * p = anArray[1]; 20 | int * q = aFunction(anArray[0][0], 21 | anArray[2], 22 | &p); 23 | for (int i =0; i < 3; i++) { 24 | for (int j = 0; j < 3; j++) { 25 | printf("%d\n", anArray[i][j]); 26 | } 27 | } 28 | printf("*q=%d\n", *q); 29 | 30 | return EXIT_SUCCESS; 31 | } 32 | -------------------------------------------------------------------------------- /23_power_rec/README: -------------------------------------------------------------------------------- 1 | Write a recursive function unsigned power(unsigned x, unsigned y) which computes x 2 | to the y power. Note that while 0 to the 0 is undefined in mathematics, 3 | we specify that 0 to the 0 shall be 1 for this function. 4 | 5 | Save it into a file called power.c 6 | 7 | You MUST use recursion (no iteration). 8 | 9 | 10 | Use your test-power.c from your previous assignment to test your implementation 11 | of power. You can symlink the file from the previous assignment into this directory: 12 | 13 | ln -s ../22_tests_power/test-power.c ./ 14 | 15 | You should then write a Makefile which will compile each C file separately 16 | to an object file, and like them together. 17 | 18 | 19 | -------------------------------------------------------------------------------- /17_read_arr2/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define NSTRS 3 6 | int main(void) { 7 | const char * strs[NSTRS] = {"apple", "bannana", "carrot"}; 8 | 9 | for (int i = 0; i < NSTRS; i++) { 10 | const char * a = strchr(strs[i], 'a'); 11 | a++; 12 | printf("%c\n", *a); 13 | printf("%c\n", a[2]); 14 | a = strstr(strs[i], "nana"); 15 | if (a != NULL) { 16 | printf("%s has %s %ld characters into it!\n", strs[i], a, a - strs[i]); 17 | } 18 | } 19 | const char * ptr = strs[2]; 20 | while (*ptr != '\0') { 21 | char x = *ptr + 3; 22 | printf("%c", x); 23 | ptr++; 24 | } 25 | printf("\n"); 26 | return EXIT_SUCCESS; 27 | } 28 | -------------------------------------------------------------------------------- /c4prj1_deck/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Mon Oct 15 06:57:26 UTC 2018 2 | Compiling deck.c -> deck.o 3 | Compiling eval.c -> eval.o 4 | Compiling cards.c -> cards.o 5 | Linking eval.o, deck.o, cards.o, and our tester 6 | Testing free_deck(deck_t *) 7 | - Test passed 8 | Testing add_card_to(deck_t *, card_t) 9 | - Test passed 10 | Testing add_empty_card(deck_t *) 11 | - Test passed 12 | Testing make_deck_exclude(deck_t *) 13 | - Test passed 14 | Testing build_remaining_deck(deck_t **, size_t) 15 | Testing with 1 hand 16 | Testing with 2 hands 17 | Testing with 3 hands 18 | Testing with 4 hands 19 | Testing with 5 hands 20 | Testing with 6 hands 21 | - Test passed 22 | Testing get_match_count(deck_t *) 23 | - Test passed 24 | 25 | Overall Grade: A 26 | -------------------------------------------------------------------------------- /06_rect/res.txt: -------------------------------------------------------------------------------- 1 | r1 is (2,3) to (7,9) 2 | r2 is (-1,-2) to (4,5) 3 | r3 is (-2,-3) to (5,7) 4 | r4 is (-4,7) to (0,9) 5 | intersection(r1,r1): (2,3) to (7,9) 6 | intersection(r1,r2): (2,3) to (4,5) 7 | intersection(r1,r3): (2,3) to (5,7) 8 | intersection(r1,r4): 9 | intersection(r2,r1): (2,3) to (4,5) 10 | intersection(r2,r2): (-1,-2) to (4,5) 11 | intersection(r2,r3): (-1,-2) to (4,5) 12 | intersection(r2,r4): 13 | intersection(r3,r1): (2,3) to (5,7) 14 | intersection(r3,r2): (-1,-2) to (4,5) 15 | intersection(r3,r3): (-2,-3) to (5,7) 16 | intersection(r3,r4): (-2,7) to (0,7) 17 | intersection(r4,r1): 18 | intersection(r4,r2): 19 | intersection(r4,r3): (-2,7) to (0,7) 20 | intersection(r4,r4): (-4,7) to (0,9) 21 | -------------------------------------------------------------------------------- /22_tests_power/next-README: -------------------------------------------------------------------------------- 1 | Do problem 7.6 in AoP: 2 | 3 | Write a recursive function unsigned power(unsigned x, unsigned y) which computes x 4 | to the y power. Note that while 0 to the 0 is undefined in mathematics, 5 | we specify that 0 to the 0 shall be 1 for this function. 6 | 7 | Save it into a file called power.c 8 | 9 | You MUST use recursion (no iteration). 10 | 11 | 12 | Use your test-power.c from your previous assignment to test your implementation 13 | of power. You can symlink the file from the previous assignment into this directory: 14 | 15 | ln -s ../16_tests_power/test-power.c ./ 16 | 17 | You should then write a Makefile which will compile each C file separately 18 | to an object file, and like them together. 19 | 20 | 21 | -------------------------------------------------------------------------------- /06_rect/rectangle_ans.txt: -------------------------------------------------------------------------------- 1 | r1 is (2,3) to (7,9) 2 | r2 is (-1,-2) to (4,5) 3 | r3 is (-2,-3) to (5,7) 4 | r4 is (-4,7) to (0,9) 5 | intersection(r1,r1): (2,3) to (7,9) 6 | intersection(r1,r2): (2,3) to (4,5) 7 | intersection(r1,r3): (2,3) to (5,7) 8 | intersection(r1,r4): 9 | intersection(r2,r1): (2,3) to (4,5) 10 | intersection(r2,r2): (-1,-2) to (4,5) 11 | intersection(r2,r3): (-1,-2) to (4,5) 12 | intersection(r2,r4): 13 | intersection(r3,r1): (2,3) to (5,7) 14 | intersection(r3,r2): (-1,-2) to (4,5) 15 | intersection(r3,r3): (-2,-3) to (5,7) 16 | intersection(r3,r4): (-2,7) to (0,7) 17 | intersection(r4,r1): 18 | intersection(r4,r2): 19 | intersection(r4,r3): (-2,7) to (0,7) 20 | intersection(r4,r4): (-4,7) to (0,9) 21 | -------------------------------------------------------------------------------- /14_array_max/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 06:04:13 UTC 2018 2 | Attempting to compile arrayMax.c 3 | ################################################# 4 | testcase1: 5 | Your file matched the expected output 6 | Your output matched what we expected 7 | Removing your main() and replacing it with our own to run more tests... 8 | ################################################# 9 | testcase2: 10 | array size:0 was Correct 11 | ################################################# 12 | testcase3: 13 | array size:1 was Correct 14 | ################################################# 15 | testcase4: 16 | array size:100 was Correct 17 | ################################################# 18 | testcase5: 19 | array size:5000 was Correct 20 | 21 | Overall Grade: A 22 | -------------------------------------------------------------------------------- /26_tests_matrix_input/run_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | run_test() { 3 | prog="$1" 4 | testfile="$2" 5 | IFS=$'\n' 6 | for line in `cat $testfile | sed 's/^$/ /'` 7 | do 8 | IFS=" " correct=`/usr/local/l2p/rot_matrix/rotateMatrix $line 2>&1` 9 | IFS=" " broken=`$prog $line 2>&1` 10 | if [ "$broken" != "$correct" ] 11 | then 12 | return 0 13 | fi 14 | done 15 | return 1 16 | } 17 | 18 | for i in /usr/local/l2p/rot_matrix/rotateMatrix* 19 | do 20 | if [ "$i" != "/usr/local/l2p/rot_matrix/rotateMatrix" ] 21 | then 22 | echo "Checking `basename $i`" 23 | run_test $i tests.txt 24 | x="$?" 25 | if [ "$x" != "0" ] 26 | then 27 | echo "***Your tests failed to show that `basename $i` was broken!" 28 | fi 29 | fi 30 | done 31 | -------------------------------------------------------------------------------- /c2prj2_testing/run_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | run_test(){ 3 | prog="$1" 4 | testfile="$2" 5 | IFS=$'\n' 6 | IFS=" " correct=`/usr/local/l2p/poker/correct-test-eval $testfile 2>&1` 7 | IFS=" " broken=`$prog $testfile 2>&1` 8 | if [ "$broken" != "$correct" ] 9 | then 10 | return 0 11 | fi 12 | return 1 13 | } 14 | 15 | found=0 16 | notfound=0 17 | for i in /usr/local/l2p/poker/test-eval-* 18 | do 19 | run_test $i tests.txt 20 | x="$?" 21 | if [ "$x" != "0" ] 22 | then 23 | echo "Your test cases did not identify the problem with `basename $i`" 24 | let notfound=${notfound}+1 25 | else 26 | let found=${found}+1 27 | fi 28 | done 29 | echo "Test cases identified $found problems" 30 | echo "Test cases failed to identify $notfound problems" 31 | -------------------------------------------------------------------------------- /09_testing2/run_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | run_test(){ 3 | prog="$1" 4 | testfile="$2" 5 | IFS=$'\n' 6 | for line in `cat $testfile` 7 | do 8 | IFS=" " correct=`/usr/local/l2p/match5/correct-match5 $line 2>&1` 9 | IFS=" " broken=`$prog $line 2>&1` 10 | if [ "$broken" != "$correct" ] 11 | then 12 | return 0 13 | fi 14 | done 15 | return 1 16 | } 17 | 18 | found=0 19 | notfound=0 20 | for i in /usr/local/l2p/match5/match5-* 21 | do 22 | run_test $i tests.txt 23 | x="$?" 24 | if [ "$x" != "0" ] 25 | then 26 | echo "Your test cases did not identify the problem with `basename $i`" 27 | let notfound=${notfound}+1 28 | else 29 | let found=${found}+1 30 | fi 31 | done 32 | echo "Test cases identified $found problems" 33 | echo "Test cases failed to identify $notfound problems" 34 | -------------------------------------------------------------------------------- /26_tests_matrix_input/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 22:13:45 UTC 2018 2 | Checking rotateMatrix1 3 | Your tests identified the problem with rotateMatrix1 4 | Checking rotateMatrix2 5 | Your tests identified the problem with rotateMatrix2 6 | Checking rotateMatrix3 7 | Your tests identified the problem with rotateMatrix3 8 | Checking rotateMatrix4 9 | Your tests identified the problem with rotateMatrix4 10 | Checking rotateMatrix5 11 | Your tests identified the problem with rotateMatrix5 12 | Checking rotateMatrix6 13 | Your tests identified the problem with rotateMatrix6 14 | Checking rotateMatrix7 15 | Your tests identified the problem with rotateMatrix7 16 | Checking rotateMatrix8 17 | Your tests identified the problem with rotateMatrix8 18 | Your tests identified problems with all broken programs 19 | 20 | Overall Grade: PASSED 21 | -------------------------------------------------------------------------------- /31_minesweeper/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Sun Oct 14 17:00:31 UTC 2018 2 | Attempting to compile minesweeper.c 3 | ################################################# 4 | testcase1: 5 | Your output is correct 6 | - Valgrind was clean (no errors, no memory leaks) 7 | valgrind was clean 8 | ################################################# 9 | testcase2: 10 | Your output is correct 11 | - Valgrind was clean (no errors, no memory leaks) 12 | valgrind was clean 13 | ################################################# 14 | testcase3: 15 | Your output is correct 16 | - Valgrind was clean (no errors, no memory leaks) 17 | valgrind was clean 18 | ################################################# 19 | testcase4: 20 | Your output is correct 21 | - Valgrind was clean (no errors, no memory leaks) 22 | valgrind was clean 23 | 24 | Overall Grade: A 25 | -------------------------------------------------------------------------------- /c4prj3_finish/provided-tests/answers.txt: -------------------------------------------------------------------------------- 1 | test01.txt: Hand 0 = 95%, Hand 1 = 5% 2 | test02.txt: Hand 0 = 14%, Hand 1 = 86% 3 | test03.txt: Hand 0 = 69%, Hand 1 = 31% 4 | test04.txt: Hand 0 = 63%, Hand 1 = 36% 5 | test05.txt: Hand 0 = 27%, Hand 1 = 73% 6 | test06.txt: Hand 0 = 20%, Hand 1 = 80% 7 | test07.txt: Hand 0 = 100%, Hand 1 = 0% 8 | test08.txt: Hand 0 = 1%, Hand 1 = 1% 9 | test09.txt: Hand 0 = 0%, Hand 1 = 4% 10 | test10.txt: Hand 0 = 0%, Hand 1 = 18% 11 | test11.txt: Hand 0 = 41%, Hand 1 = 58% 12 | test12.txt: Hand 0 = 84%, Hand 1 = 16% 13 | test13.txt: Hand 0 = 77%, Hand 1 = 23% 14 | test14.txt: Hand 0 = 0%, Hand 1 = 0%, Hand 2 = 31% 15 | test15.txt: Hand 0 = 2%, Hand 1 = 13%, Hand 2 = 84% 16 | test16.txt: Hand 0 = 4%, Hand 1 = 5%, Hand 2 = 12%, 17 | Hand 3 = 8%, Hand 4 = 58%, Hand 5 = 12% 18 | 19 | -------------------------------------------------------------------------------- /30_sort_lines/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Sat Oct 13 21:21:40 UTC 2018 2 | Attempting to compile sortLines.c 3 | ################################################# 4 | testcase1: 5 | testcase1 passed, your program successfully indicated a failure 6 | - Valgrind was clean (no errors, no memory leaks) 7 | valgrind was clean 8 | ################################################# 9 | testcase2: 10 | Your output is correct 11 | - Valgrind was clean (no errors, no memory leaks) 12 | valgrind was clean 13 | ################################################# 14 | testcase3: 15 | Your output is correct 16 | - Valgrind was clean (no errors, no memory leaks) 17 | valgrind was clean 18 | ################################################# 19 | testcase4: 20 | Your output is correct 21 | - Valgrind was clean (no errors, no memory leaks) 22 | valgrind was clean 23 | 24 | Overall Grade: A 25 | -------------------------------------------------------------------------------- /c2prj1_cards/cards.h: -------------------------------------------------------------------------------- 1 | #ifndef CARD_H 2 | #define CARD_H 3 | #define VALUE_ACE 14 4 | #define VALUE_KING 13 5 | #define VALUE_QUEEN 12 6 | #define VALUE_JACK 11 7 | typedef enum { 8 | SPADES, 9 | HEARTS, 10 | DIAMONDS, 11 | CLUBS, 12 | NUM_SUITS 13 | } suit_t; 14 | 15 | struct card_tag { 16 | unsigned value; 17 | suit_t suit; 18 | }; 19 | typedef struct card_tag card_t; 20 | typedef enum { 21 | STRAIGHT_FLUSH, 22 | FOUR_OF_A_KIND, 23 | FULL_HOUSE, 24 | FLUSH, 25 | STRAIGHT, 26 | THREE_OF_A_KIND, 27 | TWO_PAIR, 28 | PAIR, 29 | NOTHING 30 | } hand_ranking_t; 31 | card_t card_from_num(unsigned c); 32 | void assert_card_valid(card_t c); 33 | const char * ranking_to_string(hand_ranking_t r) ; 34 | char value_letter(card_t c); 35 | char suit_letter(card_t c) ; 36 | void print_card(card_t c); 37 | card_t card_from_letters(char value_let, char suit_let); 38 | #endif 39 | -------------------------------------------------------------------------------- /c4prj2_input/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Mon Oct 15 19:07:17 UTC 2018 2 | Compiling cards.c -> cards.o 3 | Compiling deck.c -> deck.o 4 | Compiling input.c -> input.o 5 | Compiling future.c -> future.o 6 | Linking input.o, future.o deck.o, cards.o, and our tester 7 | Testing with input file with 8 | o 1 hand 9 | o No unknown/future cards 10 | Your file matched the expected output 11 | Test case passed 12 | Testing with input file with 13 | o Many hands 14 | o No unknown/future cards 15 | Your file matched the expected output 16 | Test case passed 17 | Testing with input file with 18 | o Many hands 19 | o 1 unknown/future cards per hand 20 | Your file matched the expected output 21 | Test case passed 22 | Testing with input file with 23 | o Many hands 24 | o Many unknown/future cards per hand 25 | Your file matched the expected output 26 | Test case passed 27 | 28 | Overall Grade: A 29 | -------------------------------------------------------------------------------- /03_code2/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 03:06:57 UTC 2018 2 | Checking code2.c for legal syntax 3 | Checking for int printTriangle (int size) 4 | Found on line 4, column 1 5 | Checking for int main(void) 6 | Found on line 33, column 1 7 | Trying to run the code.. 8 | Your file matched the expected output 9 | Removing your main() and replacing it with our own to run more tests... 10 | Testing printTriangle(0) ... Correct 11 | Testing printTriangle(1) ... Correct 12 | Testing printTriangle(2) ... Correct 13 | Testing printTriangle(3) ... Correct 14 | Testing printTriangle(4) ... Correct 15 | Testing printTriangle(7) ... Correct 16 | Testing printTriangle(9) ... Correct 17 | Testing printTriangle(12) ... Correct 18 | Testing printTriangle(73) ... Correct 19 | Testing printTriangle(147) ... Correct 20 | Testing printTriangle(1719) ... Correct 21 | Testing printTriangle(2353) ... Correct 22 | 23 | Overall Grade: A 24 | -------------------------------------------------------------------------------- /15_tests_subseq/test-subseq.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | size_t maxSeq(int * array, size_t n); 5 | 6 | int main(){ 7 | int array1[] = {-1,1,0,1}; 8 | int array2[] = {1, 6, 10, 1, -3, 4, 5, 10}; 9 | int array3[] = {}; 10 | int array4[] = {-1,-2,-3}; 11 | int array5[] = {1,1,1,1,1}; 12 | int array6[] = {0,2,5,7,8}; 13 | 14 | if(maxSeq(array1,4) != 2){ 15 | return EXIT_FAILURE; 16 | } 17 | 18 | if(maxSeq(array2,8) != 4){ 19 | return EXIT_FAILURE; 20 | } 21 | 22 | if(maxSeq(array3,0) != 0){ 23 | return EXIT_FAILURE; 24 | } 25 | if(maxSeq(array4,3) != 1){ 26 | return EXIT_FAILURE; 27 | } 28 | if(maxSeq(array5,5) != 1){ 29 | return EXIT_FAILURE; 30 | } 31 | if(maxSeq(array6,5) != 5){ 32 | return EXIT_FAILURE; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /16_subseq/test-subseq.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | size_t maxSeq(int * array, size_t n); 5 | 6 | int main(){ 7 | int array1[] = {-1,1,0,1}; 8 | int array2[] = {1, 6, 10, 1, -3, 4, 5, 10}; 9 | // int array3[] = {}; 10 | int array4[] = {-1,-2,-3}; 11 | int array5[] = {1,1,1,1,1}; 12 | int array6[] = {0,2,5,7,8}; 13 | 14 | if(maxSeq(array1,4) != 2){ 15 | return EXIT_FAILURE; 16 | } 17 | 18 | if(maxSeq(array2,8) != 4){ 19 | return EXIT_FAILURE; 20 | } 21 | 22 | //if(maxSeq(array3,0) != 0){ 23 | // return EXIT_FAILURE; 24 | //} 25 | if(maxSeq(array4,3) != 1){ 26 | return EXIT_FAILURE; 27 | } 28 | if(maxSeq(array5,5) != 1){ 29 | return EXIT_FAILURE; 30 | } 31 | if(maxSeq(array6,5) != 5){ 32 | return EXIT_FAILURE; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /c2prj1_cards/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 05:22:59 UTC 2018 2 | Compiling cards.c 3 | Testing card_from_letters 4 | Passed 5 | Testing value_letter and suit_letter 6 | Passed 7 | Testing print_card 8 | Passed 9 | Testing card_from_num 10 | Passed 11 | Testing ranking_to_string 12 | ranking_to_string(STRAIGHT_FLUSH) resulted in STRAIGHT_FLUSH (Correct) 13 | ranking_to_string(FOUR_OF_A_KIND) resulted in FOUR_OF_A_KIND (Correct) 14 | ranking_to_string(FULL_HOUSE) resulted in FULL_HOUSE (Correct) 15 | ranking_to_string(FLUSH) resulted in FLUSH (Correct) 16 | ranking_to_string(STRAIGHT) resulted in STRAIGHT (Correct) 17 | ranking_to_string(THREE_OF_A_KIND) resulted in THREE_OF_A_KIND (Correct) 18 | ranking_to_string(TWO_PAIR) resulted in TWO_PAIR (Correct) 19 | ranking_to_string(PAIR) resulted in PAIR (Correct) 20 | ranking_to_string(NOTHING) resulted in NOTHING (Correct) 21 | Passed 22 | Testing assert_card_valid 23 | Passed 24 | 25 | Overall Grade: PASSED 26 | -------------------------------------------------------------------------------- /22_tests_power/run_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for i in /usr/local/l2p/power/power*.o 4 | do 5 | test=`basename $i | sed 's/power//' | sed 's/.o//'` 6 | if [ "$test" == "" ] 7 | then 8 | echo "**Testing correct implementation **" 9 | else 10 | echo "**Testing broken implementation ${test} **" 11 | fi 12 | echo "-------------------------------------" 13 | echo "" 14 | gcc -o test-power test-power.c $i 15 | if [ "$?" != "0" ] 16 | then 17 | echo "Could not compile test-power.c with $i" > /dev/stderr 18 | exit 1 19 | fi 20 | ./test-power 21 | if [ "$?" != 0 ] 22 | then 23 | if [ "$test" == "" ] 24 | then 25 | echo "Your test program falsely failed the correct implementation!" > /dev/stderr 26 | exit 1 27 | fi 28 | else 29 | if [ "$test" != "" ] 30 | then 31 | echo "Your test program did not identify $i as broken!" > /dev/stderr 32 | exit 1 33 | fi 34 | fi 35 | echo "" 36 | done 37 | -------------------------------------------------------------------------------- /15_tests_subseq/run_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for i in /usr/local/l2p/subseq/subseq*.o 4 | do 5 | test=`basename $i | sed 's/subseq//' | sed 's/.o//'` 6 | if [ "$test" == "" ] 7 | then 8 | echo "**Testing correct implementation **" 9 | else 10 | echo "**Testing broken implementation ${test} **" 11 | fi 12 | echo "-------------------------------------" 13 | echo "" 14 | 15 | gcc -o test-subseq test-subseq.c $i 16 | if [ "$?" != "0" ] 17 | then 18 | echo "Could not compile test-subseq.c with $i" > /dev/stderr 19 | exit 1 20 | fi 21 | ./test-subseq 22 | if [ "$?" != 0 ] 23 | then 24 | if [ "$test" == "" ] 25 | then 26 | echo "Your test program falsely failed the correct implementation!" > /dev/stderr 27 | exit 1 28 | fi 29 | else 30 | if [ "$test" != "" ] 31 | then 32 | echo "Your test program did not identify $i as broken!" > /dev/stderr 33 | exit 1 34 | fi 35 | fi 36 | echo "" 37 | done 38 | -------------------------------------------------------------------------------- /16_subseq/README: -------------------------------------------------------------------------------- 1 | For this assignment, you will be writing testcases for 2 | your next assignment (as usual, the instructions for that assignment 3 | can be found in next-README). 4 | 5 | As usual, one correct and many broken implementations can be found 6 | in /usr/local/l2p/subseq. 7 | 8 | As with power, these are provided as compiled object files, and you 9 | should write a C program (in test-subseq.c) whose main function tests 10 | the maxSeq function. As before, it should exit with EXIT_SUCCESS if all 11 | tests pass, and EXIT_FAILURE if any test fails. Note that you will 12 | need to write the prototype for maxSeq: 13 | 14 | size_t maxSeq(int * array, size_t n); 15 | 16 | in your test-subseq.c file, so that the compiler knows about the 17 | maxSeq function. The correct place to put it is after you #include 18 | any .h files you need, but before any other code you write. 19 | 20 | We have provided run_all.sh to help you run your test cases against 21 | all implementations. 22 | 23 | -------------------------------------------------------------------------------- /28_fix_vg_encr/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 23:16:05 UTC 2018 2 | Attempting to compile encrypt.c 3 | testcase1: 4 | your output was correct 5 | - Valgrind was clean (no errors, no memory leaks) 6 | valgrind was clean 7 | ################################################# 8 | testcase2: 9 | - Valgrind was clean (no errors, no memory leaks) 10 | valgrind was clean 11 | ################################################# 12 | testcase3: 13 | - Valgrind was clean (no errors, no memory leaks) 14 | valgrind was clean 15 | ################################################# 16 | testcase4: 17 | - Valgrind was clean (no errors, no memory leaks) 18 | valgrind was clean 19 | ################################################# 20 | testcase5: 21 | - Valgrind was clean (no errors, no memory leaks) 22 | valgrind was clean 23 | ################################################# 24 | testcase6: 25 | - Valgrind was clean (no errors, no memory leaks) 26 | valgrind was clean 27 | 28 | Overall Grade: A 29 | -------------------------------------------------------------------------------- /15_tests_subseq/README: -------------------------------------------------------------------------------- 1 | For this assignment, you will be writing testcases for 2 | your next assignment (as usual, the instructions for that assignment 3 | can be found in next-README). 4 | 5 | As usual, one correct and many broken implementations can be found 6 | in /usr/local/l2p/subseq. 7 | 8 | As with power, these are provided as compiled object files, and you 9 | should write a C program (in test-subseq.c) whose main function tests 10 | the maxSeq function. As before, it should exit with EXIT_SUCCESS if all 11 | tests pass, and EXIT_FAILURE if any test fails. Note that you will 12 | need to write the prototype for maxSeq: 13 | 14 | size_t maxSeq(int * array, size_t n); 15 | 16 | in your test-subseq.c file, so that the compiler knows about the 17 | maxSeq function. The correct place to put it is after you #include 18 | any .h files you need, but before any other code you write. 19 | 20 | We have provided run_all.sh to help you run your test cases against 21 | all implementations. 22 | 23 | -------------------------------------------------------------------------------- /29_outname/README: -------------------------------------------------------------------------------- 1 | In a future assignment, you are going to write a program which reads 2 | some input, does some manipulations, and produces output in another file. 3 | Right now, you are going to write a function which will be useful to you 4 | in that assignment, which takes theinput filename, and produces the output 5 | file name. The output file name should be the same as the input file name 6 | with ".counts" on the end. So, for example, if teh input filename (inputName) 7 | is "input.txt", your function should return "input.txt.counts". 8 | 9 | Note that your function needs to use malloc to allocate memory to hold 10 | the string that it will return as its answer. 11 | 12 | Your function should have the following signature: 13 | 14 | char * computeOutputFileName(const char * inputName) 15 | 16 | and you should write it in the outname.c file. 17 | You can make and test with the main function found in outname_test.c. 18 | As always, be sure your program valgrinds cleanly. 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /18_reverse_str/reverse.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void reverse(char * str) { 6 | //WRITE ME! 7 | if(str==NULL)return; 8 | size_t count = strlen(str); 9 | if(count==0 || count==1) return; 10 | char * lo = str; 11 | char * hi = lo + count - 1; 12 | for(int i=0; i< count/2; i++){ 13 | char temp = *lo; 14 | *lo = *hi; 15 | *hi = temp; 16 | lo++; 17 | hi--; 18 | } 19 | return; 20 | } 21 | 22 | int main(void) { 23 | char str0[] = ""; 24 | char str1[] = "123"; 25 | char str2[] = "abcd"; 26 | char str3[] = "Captain's log, Stardate 42523.7"; 27 | char str4[] = "Hello, my name is Inigo Montoya."; 28 | char str5[] = "You can be my wingman anyday!"; 29 | char str6[] = "Executor Selendis! Unleash the full power of your forces! There may be no tomorrow!"; 30 | char * array[] = {str0, str1, str2, str3, str4, str5, str6}; 31 | for (int i = 0; i < 7; i++) { 32 | reverse(array[i]); 33 | printf("%s\n", array[i]); 34 | } 35 | return EXIT_SUCCESS; 36 | } 37 | -------------------------------------------------------------------------------- /25_break_encr/breaker.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void getFreqArray(int *freqArr, FILE * f){ 7 | int c; 8 | while((c=fgetc(f)) != EOF){ 9 | if(isalpha(c)){ 10 | c = tolower(c); 11 | c = c - 'a'; 12 | freqArr[c] = freqArr[c]+1; 13 | } 14 | } 15 | } 16 | 17 | int maxFreqIdx(int * freqArr){ 18 | int max = freqArr[0]; 19 | int maxIdx = 0; 20 | for(int i=0; i<26; i++){ 21 | if(freqArr[i]>max){ 22 | max = freqArr[i]; 23 | maxIdx = i; 24 | } 25 | } 26 | return maxIdx; 27 | } 28 | 29 | int main(int argc, char ** argv){ 30 | if(argc!=2){ 31 | fprintf(stderr, "Usage: Wrong amount of Arguments\n"); 32 | return EXIT_FAILURE; 33 | } 34 | FILE * f = fopen(argv[1],"r"); 35 | if(f==NULL){ 36 | perror("Could not open file"); 37 | return EXIT_FAILURE; 38 | } 39 | int freqArr[26] = {0}; 40 | getFreqArray(freqArr, f); 41 | int maxIdx = maxFreqIdx(freqArr); 42 | int key = (maxIdx + 'a' - 'e' + 26)%26; 43 | printf("%d\n", key); 44 | } 45 | -------------------------------------------------------------------------------- /23_power_rec/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 18:10:51 UTC 2018 2 | Attempting to compile power.c 3 | Attempting to compile power.o with our main 4 | Checking for unsigned power (unsigned x, unsigned y) 5 | Found on line 4, column 1 6 | Checking for no iteration (do, while, for) 7 | Checking that power is recursive 8 | 0^0 was Correct 9 | 0^1 was Correct 10 | 0^2 was Correct 11 | 0^6 was Correct 12 | 0^8 was Correct 13 | 0^11 was Correct 14 | 1^0 was Correct 15 | 1^1 was Correct 16 | 1^2 was Correct 17 | 1^6 was Correct 18 | 1^8 was Correct 19 | 1^11 was Correct 20 | 4^0 was Correct 21 | 4^1 was Correct 22 | 4^2 was Correct 23 | 4^6 was Correct 24 | 4^8 was Correct 25 | 4^11 was Correct 26 | 5^0 was Correct 27 | 5^1 was Correct 28 | 5^2 was Correct 29 | 5^6 was Correct 30 | 5^8 was Correct 31 | 5^11 was Correct 32 | 9^0 was Correct 33 | 9^1 was Correct 34 | 9^2 was Correct 35 | 9^6 was Correct 36 | 9^8 was Correct 37 | 9^11 was Correct 38 | 12^0 was Correct 39 | 12^1 was Correct 40 | 12^2 was Correct 41 | 12^6 was Correct 42 | 12^8 was Correct 43 | 12^11 was Correct 44 | 45 | Overall Grade: A 46 | -------------------------------------------------------------------------------- /08_testing/README: -------------------------------------------------------------------------------- 1 | In this assignment, you will be black-box testing a few 2 | broken implementations of "isPrime". You will see 3 | that there are four broken implementations of isPrime: 4 | 5 | isPrime-broken1 6 | isPrime-broken2 7 | isPrime-broken3 8 | isPrime-broken4 9 | 10 | as well as a correct implementation: 11 | 12 | isPrime-correct 13 | 14 | All of these take one command line argument, which is the number 15 | to test for primality. For example, you might run 16 | 17 | $ ./isPrime-correct 3 18 | 3 is prime 19 | $ ./isPrime-correct 4 20 | 4 is not prime 21 | 22 | Your job is to find a test case for each broken implementation which 23 | shows that it is not correct---that is, where its behavior differs 24 | from that of isPrime-correct. 25 | 26 | For each broken program, write the input which breaks the program 27 | into a file called "input.X" where X is 1, 2, 3, or 4 (so input.1 has 28 | the command line argument that shows that isPrime-broken1 is broken). 29 | 30 | Note that isPrime-correct's behavior is considered correct, and 31 | any test case which deviates from it is considered wrong. 32 | -------------------------------------------------------------------------------- /02_code1/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat > temp.c < 4 | #include 5 | EOF 6 | cat code1.c >> temp.c 7 | gcc -Wall -Werror -pedantic -std=gnu99 temp.c -o code1 2>errors.txt 8 | if [ "$?" = "0" ] 9 | then 10 | echo "Your code appears to have legal syntax!" 11 | echo "Here is what I get when I run it..." 12 | echo "-----------------" 13 | ./code1 14 | echo "-----------------" 15 | echo "Here is what I would expect the answers to be:" 16 | echo "----------------" 17 | cat < 2 | #include 3 | 4 | struct _retire_info{ 5 | int months; 6 | double contribution; 7 | double rate_of_return; 8 | }; 9 | typedef struct _retire_info retire_info; 10 | 11 | double calculate(double initial, retire_info info, int startAge){ 12 | double res = initial; 13 | for(int i=0; i 2 | #include 3 | 4 | int * arrayMax(int * array, int n) { 5 | if (n==0) return NULL; 6 | int *p = array; 7 | int max = *p; 8 | for(int i=1; i max){ 10 | max = array[i]; 11 | p = &array[i]; 12 | } 13 | } 14 | return p; 15 | } 16 | 17 | void doTest(int * array, int n) { 18 | printf("arrayMax("); 19 | if (array == NULL) { 20 | printf("NULL"); 21 | } 22 | else { 23 | printf("{"); 24 | for (int i =0; i < n; i++) { 25 | printf("%d", array[i]); 26 | if (i < n -1) { 27 | printf(", "); 28 | } 29 | } 30 | printf("}"); 31 | } 32 | printf(", %d) is \n", n); 33 | int * p = arrayMax (array, n); 34 | if (p == NULL) { 35 | printf("NULL\n"); 36 | } 37 | else { 38 | printf("%d\n", *p); 39 | } 40 | } 41 | 42 | int main(void) { 43 | int array1[] = { 77, 33, 19, 99, 42, 6, 27, 4}; 44 | int array2[] = { -3, -42, -99, -1000, -999, -88, -77}; 45 | int array3[] = { 425, 59, -3, 77, 0, 36}; 46 | 47 | doTest (array1, 8); 48 | doTest (array2, 7); 49 | doTest (array3, 6); 50 | doTest (NULL, 0); 51 | doTest (array1, 0); 52 | 53 | return EXIT_SUCCESS; 54 | } 55 | -------------------------------------------------------------------------------- /22_tests_power/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 17:58:05 UTC 2018 2 | **Testing broken implementation 10 ** 3 | ------------------------------------- 4 | 5 | 6 | **Testing broken implementation 11 ** 7 | ------------------------------------- 8 | 9 | 10 | **Testing broken implementation 1 ** 11 | ------------------------------------- 12 | 13 | 14 | **Testing broken implementation 2 ** 15 | ------------------------------------- 16 | 17 | 18 | **Testing broken implementation 3 ** 19 | ------------------------------------- 20 | 21 | 22 | **Testing broken implementation 4 ** 23 | ------------------------------------- 24 | 25 | 26 | **Testing broken implementation 5 ** 27 | ------------------------------------- 28 | 29 | 30 | **Testing broken implementation 6 ** 31 | ------------------------------------- 32 | 33 | 34 | **Testing broken implementation 7 ** 35 | ------------------------------------- 36 | 37 | 38 | **Testing broken implementation 8 ** 39 | ------------------------------------- 40 | 41 | 42 | **Testing broken implementation 9 ** 43 | ------------------------------------- 44 | 45 | 46 | **Testing correct implementation ** 47 | ------------------------------------- 48 | 49 | 50 | All tests were ok. 51 | 52 | 53 | Overall Grade: PASSED 54 | -------------------------------------------------------------------------------- /15_tests_subseq/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 06:25:42 UTC 2018 2 | **Testing broken implementation 10 ** 3 | ------------------------------------- 4 | 5 | 6 | **Testing broken implementation 11 ** 7 | ------------------------------------- 8 | 9 | 10 | **Testing broken implementation 1 ** 11 | ------------------------------------- 12 | 13 | 14 | **Testing broken implementation 2 ** 15 | ------------------------------------- 16 | 17 | 18 | **Testing broken implementation 3 ** 19 | ------------------------------------- 20 | 21 | 22 | **Testing broken implementation 4 ** 23 | ------------------------------------- 24 | 25 | 26 | **Testing broken implementation 5 ** 27 | ------------------------------------- 28 | 29 | 30 | **Testing broken implementation 6 ** 31 | ------------------------------------- 32 | 33 | 34 | **Testing broken implementation 7 ** 35 | ------------------------------------- 36 | 37 | 38 | **Testing broken implementation 8 ** 39 | ------------------------------------- 40 | 41 | 42 | **Testing broken implementation 9 ** 43 | ------------------------------------- 44 | 45 | 46 | **Testing correct implementation ** 47 | ------------------------------------- 48 | 49 | 50 | All test programs were handled correctly 51 | 52 | Overall Grade: PASSED 53 | -------------------------------------------------------------------------------- /15_tests_subseq/next-README: -------------------------------------------------------------------------------- 1 | 2 | 1. Create a file called maxSeq.c and write the function: 3 | size_t maxSeq(int * array, size_t n); 4 | 5 | which returns the length of the maximum increasing contiguous 6 | subsequence in the array. The parameter n specifies the length 7 | of the array For example, if the array passed in were 8 | 9 | { 1, 2, 1, 3, 5, 7, 2, 4, 6, 9} 10 | 11 | this function would return 4 because the longest sequence 12 | of (strictly) increasing numbers in that array is 1, 3, 5, 7 13 | which has length 4. Note that 1,3,5,7,9 is an increasing 14 | subsequence, but is not contiguous (finding discontiguous 15 | ones efficiently takes techniques we haven't learned yet). 16 | 17 | Note that the subseqence does not need to increase at a 18 | constant rate (or follow any other pattern besides being strictly 19 | increasing). 2, 4, 67, 93, 94, 102 would be a valid increasing 20 | sequence of length 6. 21 | 22 | 23 | 2. Compile and test your code using the test-subseq.c you wrote 24 | previously. (as before, compile the .c files separately, and link 25 | them together). 26 | 27 | 3. Submit your code for maxSeq.c 28 | 29 | 30 | Hint: 31 | Can you abstract a complex step out into a simple function? -------------------------------------------------------------------------------- /03_code2/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat > temp.c < 4 | #include 5 | EOF 6 | cat code2.c >> temp.c 7 | gcc -Wall -Werror -pedantic -std=gnu99 temp.c -o code2 2>errors.txt 8 | if [ "$?" = "0" ] 9 | then 10 | echo "Your code appears to have legal syntax!" 11 | echo "Here is what I get when I run it..." 12 | echo "-----------------" 13 | ./code2 14 | echo "-----------------" 15 | echo "Here is what I would expect the answers to be:" 16 | echo "----------------" 17 | cat < 2 | #include 3 | #include 4 | 5 | int getNthBit(uint32_t number, int bit) { 6 | if (bit <0 || bit >= 32) { 7 | printf("Bit %d is invalid\n", bit); 8 | exit (EXIT_FAILURE); 9 | } 10 | return (number & (1< ", nums[i], nums[i]); 33 | for (int j = 0; j < 32; j++) { 34 | printf("%d", bits[i*32 + j]); 35 | } 36 | printf("\n"); 37 | } 38 | } 39 | 40 | int main(void) { 41 | uint32_t array1[] = { 1, 2, 3, 4, 5, 15, 109}; 42 | uint32_t array2[] = { 123456789, 987654321 }; 43 | int bits[7*32-1]; 44 | doTest (array1, 7); 45 | doTest (array2, 2); 46 | numToBits(array1,7, bits , 7*32-1); 47 | return EXIT_SUCCESS; 48 | } 49 | -------------------------------------------------------------------------------- /and_beyond/README: -------------------------------------------------------------------------------- 1 | Congratulations! You have finsihed the project for Course 4 (and hopefully 2 | the entire Specialization). 3 | 4 | At this point, you have solid programming fundementals to build from. 5 | (and in fact, if you want to add more fancy features to your project 6 | [wild cards? folded hands? strange poker variants?] you could do it.) 7 | 8 | Hopefully you are hungry to learn more programming. Where can you go from here? 9 | 10 | We recommend "Object Oriented Programming in Java": 11 | 12 | https://www.coursera.org/specializations/object-oriented-programming 13 | 14 | which is a Coursera Specialization brought to you jointly by Duke 15 | and University of California San Diego. This specialization assumes 16 | you have good programming fundementals (which you do from this specialization), 17 | and teaches you Java and Object Orientated Programming (Drew is also 18 | one of the instructors on two of hte courser). 19 | 20 | If you really want to learn a LOT more programming from Drew and Geneveive, 21 | you could think about coming to Duke and studying in the ECE department. 22 | Duke ECE has great undergraduate and Masters programs with excellent 23 | courses on programming! 24 | 25 | Whatever you choose to do, we wish you good luck and happy programming! 26 | 27 | -- 28 | Drew, Genevieve, and Anne 29 | 30 | -------------------------------------------------------------------------------- /03_code2/code2.c: -------------------------------------------------------------------------------- 1 | 2 | int printTriangle(int size) { 3 | //start with starCount being 0 4 | int starCount = 0; 5 | //count from 0 (inclusive) to size (exclusive), for each number i that you count 6 | for(int i=0; i 2 | #include 3 | #include 4 | int getSecretNumber(void); //prototype, implemented elsewhere. 5 | 6 | int getOtherSN(int which); //prototype, implemented elsewhere. 7 | 8 | int main(void) { 9 | int guessesMade = 0; 10 | int yourGuess; 11 | char buffer[1024]; 12 | int myNumber = getSecretNumber(); 13 | 14 | printf("I'm thinking of a number...\n"); 15 | printf("What number do you guess?\n"); 16 | if(fgets(buffer, 1024, stdin) == NULL) { 17 | printf("Oh no, you are giving up? You lose...\n"); 18 | return EXIT_FAILURE; 19 | } 20 | yourGuess = atoi(buffer); 21 | if(yourGuess != myNumber) { 22 | printf("I'm sorry, that is not right. You lose\n"); 23 | return EXIT_FAILURE; 24 | } 25 | printf("Correct! You win round1!\n"); 26 | 27 | int total = 0; 28 | for (int i = 0; i <= 5678; i++) { 29 | total = total ^ getOtherSN(i); 30 | } 31 | printf("Ok, time for round 2. I have another secret number.\n"); 32 | printf("Your guess:\n"); 33 | if(fgets(buffer, 1024, stdin) == NULL) { 34 | printf("Oh no, you are giving up? You lose...\n"); 35 | return EXIT_FAILURE; 36 | } 37 | yourGuess = atoi(buffer); 38 | if (yourGuess == total) { 39 | printf("You win round 2 also!\n"); 40 | return EXIT_SUCCESS; 41 | } 42 | printf("Sorry, you did not win the second round\n"); 43 | return EXIT_FAILURE; 44 | } 45 | -------------------------------------------------------------------------------- /28_fix_vg_encr/README: -------------------------------------------------------------------------------- 1 | In a previous problem, you executed a Ceaser Cipher encryption program by hand. 2 | That program read an input file, and wrote to standard output. 3 | 4 | In this problem, you are going to work on a slightly modified version of that program, 5 | which is is included in encrypt.c. The major difference between this version 6 | of the program and the previous one is that rather than printing to stdout, 7 | this program appends ".enc" to the input file name, and writes its output to that 8 | file (for example, if your input file is called "input.txt", it will write to "input.txt.enc"). 9 | Additionally, rather than using fgetc to read one character at a time, this version 10 | of the program uses getline to read an entire line at a time. 11 | 12 | This program has the basic algorithm correct, but makes a variety of errors---all of which 13 | valgrind will detect. Your job for this problem is to fix the program by making it 14 | valgrind cleanly. 15 | 16 | Hint: Start from the first valgrind error. Read and understand the error. It will 17 | tell you on what line of code valgrind detected the problem. Understand the 18 | error, and why it is occuring (drawing some pictures will likely help here). 19 | Fix the error, make, and re-run. Repeat the process until all valgrind errors are 20 | gone. Don't forget that gdb may be useful as well. 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /02_code1/README: -------------------------------------------------------------------------------- 1 | Open the code1.c file you have in this directory. 2 | You will see two functions: max and main. 3 | 4 | In max, the algorithm is written as comments, but there is no code. 5 | You should translate this algorithm to code. 6 | 7 | In main, there are three print statements which call max and print 8 | its result. These would let you check if max is working right. 9 | 10 | There is also a comment asking you to write one more print statement 11 | with a call to max. In that comment, it asks you to take the max 12 | of two numbers (written as hex), and print them out. 13 | Add a line of code to do this. 14 | 15 | When you have done this, run 16 | 17 | ./test.sh 18 | 19 | This script will try to compile your code (which you will learn about in 20 | the next chapter), as well as run it. If your code does not have legal 21 | syntax, it will do its best to describe what is wrong. If there 22 | is a problem, look at the code and try to see where you did not follow 23 | the syntax rules from chapter 2. The line number and message it gives 24 | may help you find the problem. If you cannot find the problem after a minute 25 | or two, ask for help. 26 | 27 | If your code has legal syntax, test.sh will also run it, and show 28 | you the output it produced, as well as the output we expected. 29 | 30 | If they are the same, you should commit, push, and grade. 31 | 32 | If they are not, you should see if you can fix the problem (and ask for help 33 | if you cannot). 34 | -------------------------------------------------------------------------------- /20_rot_matrix/README: -------------------------------------------------------------------------------- 1 | For this problem, you will be writing a function which 2 | performs a 90 degree clockwise rotation of a 10x10 matrix. 3 | There is nothing special about a 10x10 matrix---we are just 4 | fixing the size so that you can read the input in a future 5 | assignment after you have learned about reading files, 6 | but before you have learned about dynamic memory allocation. 7 | 8 | In particular, you should write 9 | 10 | void rotate(char matrix[10][10]) 11 | 12 | in a file called rotate.c 13 | 14 | This function takes a 10 by 10 matrix of characters and rotates 15 | it 90 degrees clockwise, updating the matrix that was passed in 16 | (remember that arrays are pointers, so you will modify 17 | the array in the frame where it was created). 18 | 19 | As you hav enot yet learned to read from files, we have 20 | provided a compiled object file, read-matrix.o. This 21 | object file has a main function which will read 22 | the input file (specified as a command line arugments 23 | to your program), call your rotate function, and 24 | then print the result. 25 | 26 | If you compiled your code (and linked with read-matrix.o) 27 | into a program called rotate-matrix, you might run it as 28 | 29 | ./rotate-matrix sample.txt 30 | 31 | It will then print the resulting matrix, which in this case 32 | should look like the contents of the file sample.out. 33 | (Remember that you can use > to redirect the output 34 | of a program to a file, and use diff to compare 35 | the contents of two files). 36 | -------------------------------------------------------------------------------- /03_code2/README: -------------------------------------------------------------------------------- 1 | Open the code2.c file you have in this directory. 2 | You will see two functions: printTriangle and main. 3 | 4 | As with the previous problem, the printTriangle function 5 | has an algorithm written as comments, but there is no code. 6 | You should translate this algorithm to code. 7 | 8 | In main, there are three print statements which print out a triangle 9 | with height 4, and the total number of stars in that triangle (returned 10 | by the printTriangle function). 11 | 12 | There is also a comment asking you to write a few more statements 13 | to do the same thing for a triangle of height 7. 14 | Add the code to do this. 15 | 16 | When you have done this, run 17 | 18 | ./test.sh 19 | 20 | As before, this script will try to compile your code (which you will learn about 21 | ina n upcoming lesson), as well as run it. If your code does not have legal 22 | syntax, it will do its best to describe what is wrong. If there 23 | is a problem, look at the code and try to see where you did not follow 24 | the syntax rules from Course 1 The line number and message it gives 25 | may help you find the problem. If you cannot find the problem after a minute 26 | or two, ask for help. 27 | 28 | If your code has legal syntax, test.sh will also run it, and show 29 | you the output it produced, as well as the output we expected. 30 | 31 | If they are the same, you should commit, push, and grade. 32 | 33 | If they are not, you should see if you can fix the problem (and ask for help 34 | if you cannot). 35 | -------------------------------------------------------------------------------- /c2prj2_testing/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 05:25:32 UTC 2018 2 | Your test cases identified the problem with test-eval-0000 3 | Your test cases identified the problem with test-eval-0001 4 | Your test cases identified the problem with test-eval-0002 5 | Your test cases identified the problem with test-eval-0003 6 | Your test cases identified the problem with test-eval-0004 7 | Your test cases identified the problem with test-eval-0005 8 | Your test cases identified the problem with test-eval-0006 9 | Your test cases identified the problem with test-eval-0007 10 | Your test cases identified the problem with test-eval-0008 11 | Your test cases identified the problem with test-eval-0009 12 | Your test cases identified the problem with test-eval-0010 13 | Your test cases identified the problem with test-eval-0011 14 | Your test cases identified the problem with test-eval-0012 15 | Your test cases identified the problem with test-eval-0013 16 | Your test cases identified the problem with test-eval-0014 17 | Your test cases identified the problem with test-eval-0015 18 | Your test cases identified the problem with test-eval-0016 19 | Your test cases identified the problem with test-eval-0017 20 | Your test cases identified the problem with test-eval-0018 21 | Your test cases identified the problem with test-eval-0019 22 | Your test cases identified the problem with test-eval-0020 23 | Your test cases identified the problem with test-eval-0021 24 | Your test cases identified the problem with test-eval-0022 25 | 26 | Overall Grade: PASSED 27 | -------------------------------------------------------------------------------- /c4prj2_input/future.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "future.h" 4 | 5 | void add_future_card(future_cards_t * fc, size_t index, card_t * ptr){ 6 | size_t size = 0; 7 | if(fc==NULL){ 8 | fc = (future_cards_t *)realloc(fc, sizeof(*fc)); 9 | fc->decks = NULL; 10 | fc->n_decks = 0; 11 | } 12 | if(index >= fc->n_decks){ 13 | fc->decks = (deck_t *)realloc(fc->decks, (index+1)*sizeof(*(fc->decks))); 14 | size = fc->n_decks; 15 | fc->n_decks = index + 1; 16 | for(size_t i=size; in_decks; i++){ 17 | (fc->decks[i]).cards = (card_t **)malloc(sizeof(*(fc->decks[i].cards))); 18 | (fc->decks[i]).cards = NULL; 19 | (fc->decks[i]).n_cards = 0; 20 | } 21 | } 22 | size_t nw_n_cards = (fc->decks[index]).n_cards + 1; 23 | (fc->decks[index]).cards = (card_t **)realloc((fc->decks[index]).cards, nw_n_cards*sizeof(*(fc->decks[index].cards))); 24 | (fc->decks[index]).n_cards++; 25 | (fc->decks[index]).cards[nw_n_cards-1] = ptr; 26 | } 27 | 28 | void future_cards_from_deck(deck_t * deck, future_cards_t * fc){ 29 | if(fc==NULL){ 30 | fprintf(stderr, "Null future cards"); 31 | } 32 | if(fc->n_decks > deck->n_cards){ 33 | fprintf(stderr, "Not enough cards in deck"); 34 | } 35 | deck_t d; 36 | card_t *c; 37 | for(size_t i=0; in_decks; i++){ 38 | c = deck->cards[i]; 39 | d = fc->decks[i]; 40 | for(size_t j=0; j 2 | #include 3 | #include 4 | #include "counts.h" 5 | counts_t * createCounts(void) { 6 | //WRITE ME 7 | counts_t * res = malloc(sizeof(*res)); 8 | res -> array = NULL; 9 | res -> sz = 0; 10 | res -> unknowSz = 0; 11 | return res; 12 | } 13 | void addCount(counts_t * c, const char * name) { 14 | //WRITE ME 15 | if(name==NULL){ 16 | (c -> unknowSz)++; 17 | return; 18 | } 19 | int find_flag = 0; 20 | size_t size = c->sz; 21 | for(size_t i=0; iarray[i]->str; 23 | if(strcmp(str,name) == 0){ 24 | (c->array[i])->counts++; 25 | find_flag = 1; 26 | break; 27 | } 28 | } 29 | if(find_flag==0){ 30 | c->array = realloc(c->array, (c->sz+1)*sizeof(*(c->array))); 31 | one_count_t * ptr = malloc(sizeof(*ptr)); 32 | ptr -> str = NULL; 33 | ptr -> str = realloc(ptr->str, (strlen(name)+1)*sizeof(*(ptr->str))); 34 | strcpy(ptr->str, name); 35 | ptr->counts = 1; 36 | c->array[c->sz] = ptr; 37 | c->sz++; 38 | } 39 | } 40 | void printCounts(counts_t * c, FILE * outFile) { 41 | //WRITE ME 42 | for(size_t i=0; isz; i++){ 43 | fprintf(outFile, "%s: %d\n", c->array[i]->str, c->array[i]->counts); 44 | } 45 | if(c->unknowSz > 0){ 46 | fprintf(outFile, " : %d\n", (int)c->unknowSz); 47 | } 48 | } 49 | 50 | void freeCounts(counts_t * c) { 51 | //WRITE ME 52 | for(size_t i=0; isz; i++){ 53 | free(c->array[i]->str); 54 | free(c->array[i]); 55 | } 56 | free(c->array); 57 | free(c); 58 | } 59 | -------------------------------------------------------------------------------- /28_fix_vg_encr/encrypt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void encrypt(FILE * f, int key, FILE * outfile){ 7 | char * line = NULL; 8 | size_t sz; 9 | while (getline(&line,&sz, f) >= 0) { 10 | char * ptr = line; 11 | while (*ptr != '\0') { 12 | int c = *ptr; 13 | if (isalpha(c)) { 14 | c = tolower(c); 15 | c -= 'a'; 16 | c += key; 17 | c %= 26; 18 | c += 'a'; 19 | } 20 | *ptr = c; 21 | ptr++; 22 | } 23 | fprintf(outfile, "%s", line); 24 | } 25 | free(line); 26 | } 27 | 28 | int main(int argc, char ** argv) { 29 | if (argc != 3) { 30 | fprintf(stderr,"Usage: encrypt key inputFileName\n"); 31 | return EXIT_FAILURE; 32 | } 33 | int key = atoi(argv[1]); 34 | if (key == 0) { 35 | fprintf(stderr,"Invalid key (%s): must be a non-zero integer\n", argv[1]); 36 | return EXIT_FAILURE; 37 | } 38 | FILE * f = fopen(argv[2], "r"); 39 | if (f == NULL) { 40 | perror("Could not open file"); 41 | return EXIT_FAILURE; 42 | } 43 | //outfileNAme is argv[2] + ".txt\0", so add 5 to its length. 44 | char * outFileName = malloc((strlen(argv[2]) + 5) * sizeof(*outFileName)); 45 | strcpy(outFileName, argv[2]); 46 | strcat(outFileName, ".enc"); 47 | FILE * outFile = fopen(outFileName, "w"); 48 | encrypt(f,key, outFile); 49 | if (fclose(outFile) != 0) { 50 | perror("Failed to close the input file!"); 51 | return EXIT_FAILURE; 52 | } 53 | if (fclose(f) != 0) { 54 | perror("Failed to close the input file!"); 55 | return EXIT_FAILURE; 56 | } 57 | free(outFileName); 58 | return EXIT_SUCCESS; 59 | } 60 | -------------------------------------------------------------------------------- /05_squares/squares.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int max(int x, int y){ 5 | return (x>y)? x:y; 6 | } 7 | 8 | void squares(int size1, int x_offset, int y_offset, int size2) { 9 | //compute the max of size1 and (x_offset + size2). Call this w 10 | int w = max(size1,x_offset+size2); 11 | //compute the max of size1 and (y_offset + size2). Call this h 12 | int h = max(size1, y_offset+size2); 13 | //count from 0 to h. Call the number you count with y 14 | for(int y=0; y=x_offset && x=y_offset && y 2 | #include 3 | #include 4 | #include 5 | #include "input.h" 6 | 7 | size_t strToInt(char * str){ 8 | size_t len = strlen(str); 9 | size_t res = 0; 10 | size_t delata = 0; 11 | for(size_t i=0; in_cards = 0; 50 | ret_d->cards = NULL; 51 | 52 | while(str[count]!='\0'){ 53 | if(!isalpha(str[count]) && !isdigit(str[count]) && (str[count] != '?')){ 54 | count++; 55 | }else{ 56 | lstIdx = getLastIndex(str,count); 57 | if(lstIdx == -1){ 58 | return NULL; 59 | } 60 | if(str[count]=='?'){ 61 | c_name = (char *)realloc(c_name,(lstIdx-count+1)*sizeof(*c_name)); 62 | c_name = strncpy(c_name, str+count, (size_t)(lstIdx-count)); 63 | c_name[lstIdx-count] = '\0'; 64 | idx = strToInt(c_name+1); 65 | add_card = add_empty_card(realloc) 66 | } 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /27_matrix_input/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 22:38:12 UTC 2018 2 | Attempting to compile rotateMatrix.c 3 | testcase1 passed 4 | ################################################# 5 | testcase2: NonExistentFile 6 | (should indicate an error) 7 | testcase2 passed 8 | ################################################# 9 | testcase3: blank.txt 10 | (should indicate an error) 11 | testcase3 passed 12 | ################################################# 13 | testcase4: short-line.txt 14 | (should indicate an error) 15 | testcase4 passed 16 | ################################################# 17 | testcase5: short-file.txt 18 | (should indicate an error) 19 | testcase5 passed 20 | ################################################# 21 | testcase6: long-line.txt 22 | (should indicate an error) 23 | testcase6 passed 24 | ################################################# 25 | testcase7: long-file.txt 26 | (should indicate an error) 27 | testcase7 passed 28 | ################################################# 29 | testcase8: long-line-2.txt 30 | (should indicate an error) 31 | testcase8 passed 32 | ################################################# 33 | testcase9: normal1.txt normal2.txt 34 | (should indicate an error) 35 | testcase9 passed 36 | ################################################# 37 | testcase10: normal1.txt 38 | Your file matched the expected output 39 | testcase10 passed 40 | ################################################# 41 | testcase10: normal2.txt 42 | Your file matched the expected output 43 | testcase10 passed 44 | ################################################# 45 | testcase10: normal3.txt 46 | Your file matched the expected output 47 | testcase10 passed 48 | ################################################# 49 | testcase10: eof.txt 50 | Your file matched the expected output 51 | testcase10 passed 52 | 53 | Overall Grade: A 54 | -------------------------------------------------------------------------------- /00_hello/README: -------------------------------------------------------------------------------- 1 | This assignment is a walkthrough for you to use 2 | emacs, git, and the grading system. Your goal 3 | is to create a file called "hello.txt" with one line 4 | in it, that says 5 | 6 | hello 7 | 8 | 9 | 10 | (1) Use emacs to open/create a file called hello.txt 11 | o Type C-x C-f (Control x, then Control f) [which opens 12 | a new file] 13 | o type hello.txt [then hit enter] 14 | o Split the screen (C-x 2) and then change one half to 15 | show this buffer (C-x b , should say default: README, if so hit 16 | Enter. If not, type README, then hit Enter). Then use 17 | "C-x o" to move back into the hello.txt buffer. 18 | (2) Write one line, that says hello [then hit enter---we generally 19 | end files with a newline] 20 | (3) Save the file: C-x C-s 21 | (4) Add/commit/push it to git 22 | Suspend emacs with C-z then run the following commands 23 | git add hello.txt 24 | git commit -m "Did assignment 0" 25 | git push 26 | fg 27 | The last of these will bring emacs back 28 | 29 | (5) Grade the assignment, get your feedback (and the next assignment) 30 | Suspend emacs (C-z) 31 | grade 32 | git pull 33 | fg 34 | 35 | (6) Now, open up your grade.txt file in emacs (C-x C-f grade.txt) 36 | so you can read your feedback. Don't forget that you can 37 | change back to this buffer with C-x b, and/or split the screen 38 | with C-x 2 39 | When you are done, you can quit Emacs with C-x C-c. 40 | 41 | (7) Did something go wrong? If so, fix it, and add/push/commit/grade 42 | again. If everything went right, you should have your gotten 43 | your next assignment when you did git pull. After you quit emacs, 44 | cd to that directory: 45 | cd ../01_apple 46 | and open the README there in emacs. Follow its instructions! 47 | -------------------------------------------------------------------------------- /34_put_together/README: -------------------------------------------------------------------------------- 1 | We are now ready for the last piece: 2 | - compute the counts of values that appear in a particular input file 3 | 4 | And then to put all the pieces together. Before you start, notice that 5 | we have placed symlinks (short for "symbolic links") to the files you worked on 6 | in the previous problems. Symbolic links basically mean that when you open 7 | the file, it will open the file it links to (so opening counts.c will open 8 | ../27_counts/counts.c ). 9 | 10 | For this problem, you will start by writing the function: 11 | 12 | counts_t * countFile(const char * filename, kvarray_t * kvPairs) 13 | 14 | in the main.c file. Note that you will find it quite helpful to use several of the functions 15 | you wrote in the previous problems (in fact, much of the work should already be done). 16 | 17 | Once you have written countFile, it is time to write your main function. You 18 | will also write this function in the main.c file. Note that we have already 19 | written the high-level algorithm for the main function as comments, so you can 20 | just translate this algorithm to code. You will also need to add some error 21 | checking. 22 | 23 | Once you finish writing these two functions, you should have a working program! 24 | Compile, test, and debug it. 25 | 26 | We have provided two test cases, and the correct output for them. 27 | 28 | The first test case: 29 | ./count_values kvs1.txt list1a.txt list1b.txt 30 | 31 | should produce two output files (list1a.txt.counts and list1b.txt.counts). 32 | The correct contents can be found in list1a.txt.ans and list1b.txt.ans. 33 | 34 | The second test case: 35 | ./count_values kvs2.txt list2a.txt list2b.txt list2c.txt 36 | 37 | should produce 3 files (named appropriately) and the answers can be found in 38 | similarly named .ans files. 39 | 40 | Use git add . to submit your work. -------------------------------------------------------------------------------- /34_put_together/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Mon Oct 15 06:23:53 UTC 2018 2 | Attempting to compile: 3 | rm -f outname.o counts.o main.o kv.o count_values *~ 4 | gcc -c -Wall -Werror -std=gnu99 -pedantic -ggdb3 outname.c 5 | gcc -c -Wall -Werror -std=gnu99 -pedantic -ggdb3 counts.c 6 | gcc -c -Wall -Werror -std=gnu99 -pedantic -ggdb3 main.c 7 | gcc -c -Wall -Werror -std=gnu99 -pedantic -ggdb3 kv.c 8 | gcc -Wall -Werror -std=gnu99 -pedantic -ggdb3 -o count_values outname.o counts.o main.o kv.o 9 | ################################################# 10 | testcase1: 11 | testcase1 passed, your program successfully indicated a failure 12 | - Valgrind was clean (no errors, no memory leaks) 13 | valgrind was clean 14 | ################################################# 15 | testcase2: 16 | Your file matched the expected output 17 | Comparing file list1a.txt.counts with answer 18 | Your output is correct 19 | Comparing file list1b.txt.counts with answer 20 | Your file matched the expected output 21 | Your output is correct 22 | - Valgrind was clean (no errors, no memory leaks) 23 | valgrind was clean 24 | ################################################# 25 | testcase3: 26 | Your file matched the expected output 27 | Comparing file list2a.txt.counts with answer 28 | Your output is correct 29 | Comparing file list2b.txt.counts with answer 30 | Your file matched the expected output 31 | Your output is correct 32 | Comparing file list2c.txt.counts with answer 33 | Your file matched the expected output 34 | Your output is correct 35 | - Valgrind was clean (no errors, no memory leaks) 36 | valgrind was clean 37 | ################################################# 38 | testcase4: 39 | Your file matched the expected output 40 | Comparing file list3a.txt.counts with answer 41 | Your output is correct 42 | - Valgrind was clean (no errors, no memory leaks) 43 | valgrind was clean 44 | 45 | Overall Grade: A 46 | -------------------------------------------------------------------------------- /26_tests_matrix_input/README: -------------------------------------------------------------------------------- 1 | For this assignment, you will be writing test cases for your next 2 | assignment. As usual, the instructions for the next assignment are 3 | in next-README. 4 | 5 | For this assignment, we have created compiled binaries (in 6 | /usr/local/l2p/rot_matrix/ where rotateMatrix is correct, 7 | and the numbered ones are each broken in some way). 8 | 9 | As with 09_testing2, you will write a file called tests.txt, 10 | which will list the command line arguments you want to use to 11 | run the programs. However, unlike 09_testing2, you will 12 | also want to create a wide variety of input files. You can 13 | name them anything you want, as long as you save them in the 14 | current (20_tests_matrix_input) directory, and submit them 15 | along with tests.txt. 16 | 17 | As usual, we have provided run_all.sh 18 | 19 | Hint 1: think about various error cases that the programmer 20 | might have forgotten! 21 | 22 | Hint 2: The trickiest of these is one in which the programmer 23 | did not pay attention to a rather subtle, but common mistake 24 | pointed out in AOP! 25 | 26 | Hint 3: If you find yourself needing to create an input 27 | file with non-typable/non-printable characters in it, 28 | you will want to do a few things. 29 | 30 | First, (after you have the file you want to edit open), you 31 | will want to force emacs to change the encoding it uses 32 | (so that it won't try to rewrite things in Unicode, for example): 33 | 34 | M-x revert-buffer-with-coding-system 35 | raw-text 36 | 37 | Once you have done this, you can do 38 | 39 | M-x hexl-mode 40 | 41 | to put emacs in hex editor mode. 42 | 43 | Then you will see hex values on the left, and their printable 44 | interpreations (or . for non-printable characters) on the right. 45 | Move the point to where you want to put a particular value, and do 46 | 47 | C-M-x 48 | 49 | then type the hex value (one byte, so two hex digits) that you want, 50 | and hit enter. It will overwrite the current character with that value. 51 | Then you can save the file. 52 | -------------------------------------------------------------------------------- /27_matrix_input/README: -------------------------------------------------------------------------------- 1 | In a previous function, you write a function 2 | 3 | void rotate(char matrix[10][10]) 4 | 5 | which performed 90 degree clockwise rotation of a 10x10 6 | matrix. In that assignment, we gave you a compiled 7 | object file which read the input matrix from a file, 8 | called your function to do the rotation, and then 9 | printed the result to the screen. 10 | 11 | In this assignment, you will write the code that we 12 | previously gave you, making the complete program on your own. 13 | You are encouraged to make use of your previously written 14 | rotate function in this assignment. 15 | 16 | For this problem, you will be writing a program which 17 | performs a 90 degree clockwise rotation of a 10x10 matrix. 18 | There is nothing special about a 10x10 matrix---I just need 19 | to fix the matrix size, since we have not learned about dynamic 20 | memory allocation yet, so we do not have the knowledge needed 21 | to read in any size of matrix. 22 | 23 | To keep the input processing simple, the matrix will be a matrix 24 | of characters (so you will have something like 25 | char matrix[10][10] 26 | in your program), which will be read from a file. Each line 27 | in the input file should contain 10 characters (plus a newline). 28 | 29 | Requirements: 30 | ============= 31 | - Create a file called rotateMatrix.c 32 | - Your program will take one command line argument, a string 33 | specifying the input file to read. 34 | - The input file should contain 10 lines, each of which 35 | have 10 (non-newline) characters (plus a newline). 36 | - Your program should then rotate this 90 degrees clockwise, 37 | and print the result on stdout. 38 | Note that sample.txt provides sample input, and 39 | sample.out provides sample output. 40 | - If there are any errors, your program should print an 41 | appropriate message to stderr, and exit with EXIT_FAILURE. 42 | 43 | Hints: 44 | ------ 45 | - You may find the strchr useful for error checking that 46 | you read a proper line (10 non-newline characters, then a newline). 47 | -------------------------------------------------------------------------------- /26_tests_matrix_input/next-README: -------------------------------------------------------------------------------- 1 | In a previous function, you write a function 2 | 3 | void rotate(char matrix[10][10]) 4 | 5 | which performed 90 degree clockwise rotation of a 10x10 6 | matrix. In that assignment, we gave you a compiled 7 | object file which read the input matrix from a file, 8 | called your function to do the rotation, and then 9 | printed the result to the screen. 10 | 11 | In this assignment, you will write the code that we 12 | previously gave you, making the complete program on your own. 13 | You are encouraged to make use of your previously written 14 | rotate function in this assignment. 15 | 16 | For this problem, you will be writing a program which 17 | performs a 90 degree clockwise rotation of a 10x10 matrix. 18 | There is nothing special about a 10x10 matrix---I just need 19 | to fix the matrix size, since we have not learned about dynamic 20 | memory allocation yet, so we do not have the knowledge needed 21 | to read in any size of matrix. 22 | 23 | To keep the input processing simple, the matrix will be a matrix 24 | of characters (so you will have something like 25 | char matrix[10][10] 26 | in your program), which will be read from a file. Each line 27 | in the input file should contain 10 characters (plus a newline). 28 | 29 | Requirements: 30 | ============= 31 | - Create a file called rotateMatrix.c 32 | - Your program will take one command line argument, a string 33 | specifying the input file to read. 34 | - The input file should contain 10 lines, each of which 35 | have 10 (non-newline) characters (plus a newline). 36 | - Your program should then rotate this 90 degrees clockwise, 37 | and print the result on stdout. 38 | Note that sample.txt provides sample input, and 39 | sample.out provides sample output. 40 | - If there are any errors, your program should print an 41 | appropriate message to stderr, and exit with EXIT_FAILURE. 42 | 43 | Hints: 44 | ------ 45 | - You may find the strchr useful for error checking that 46 | you read a proper line (10 non-newline characters, then a newline). 47 | -------------------------------------------------------------------------------- /05_squares/README: -------------------------------------------------------------------------------- 1 | 1. Open the file "squares.c". Inside this file, 2 | you will find that I have already done steps 1--4 3 | for an algorithm which draws two (possibly overlapping) 4 | squares (one of #s and one of *s). 5 | 6 | 2. Read the generalized steps that I have written as comments 7 | in this file. Note that whenever I indicate a range 8 | (count from x to y, or between x and y), the range is 9 | inclusive of the lower bound, and exclusive of the upper bound. 10 | All counting is "count up by one." Determine if there are 11 | any parts of these steps that you will want to abstract 12 | out into a separate function. 13 | 14 | 3. Implement this algorithm by translating my steps into code. 15 | You may abstract any pieces you want out into separate functions. 16 | If you do so, write these new functions above the "squares" function 17 | when you finish translating it. 18 | 19 | 4. We have provided squares_test.o, which has a main function 20 | that takes four command line arguments (size1, x_offset, y_offset, size2), 21 | and calls your squares function with those arguments. 22 | You can compile your code and link it with this object file 23 | to make a program: 24 | gcc -o squares -Wall -Werror -std=gnu99 --pedantic squares.c squares_test.o 25 | Then you can run it like this: 26 | ./square 4 1 2 3 27 | which would call your squares function with 28 | size1=4 29 | x_offset=1 30 | y_offset=2 31 | size2=3 32 | 33 | which should produce output that looks like this: 34 | #### 35 | # # 36 | #*** 37 | #*#* 38 | *** 39 | We have also provided 3 files which show the correct output for three inputs 40 | (./squares 3 5 8 2,./squares 5 2 4 6,./squares 9 2 3 4) in the files 41 | whose names starts with ans_ (and then has the parameter values in its name, 42 | separated by _s). 43 | 44 | Use "diff" like you just learned to compare your program's output 45 | to the correct output. 46 | 47 | 5. Submit your modified squares.c file (git commit/git push/grade). 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /19_bits_arr/README: -------------------------------------------------------------------------------- 1 | For this problem, you will be splitting numbers (a 32 bit integer) 2 | up into their individual bits. I have provided a function for you 3 | (getNthBit) which will return a specific bit from a number. For example, 4 | getNthBit(x,0) would return the first (0th) bit, getNthBit(x,1) would 5 | return the next bit, and so on. 6 | 7 | While we normally use "int" for our numbers, we are using "uint32_t". 8 | This is just like "int" except that they are unsigned ints which are 9 | guaranteed to be 32 bits long (by contrast, the normal "int" type 10 | is signed, and there are no guarantees as to how many bits are in it). 11 | We are doing this to be precise and correct: you can use a uint32_t 12 | in much the same way as an int. 13 | 14 | 1. Open the file numToBits.c 15 | Find the function 16 | 17 | void numToBits(uint32_t * nums, int nNums, int * bits, int nBits) ; 18 | 19 | This function takes in two arrays: nums (of length nNums), and 20 | bits (of length nBits). This function should: 21 | - Check that there is enough space in bits to hold all the bits 22 | of "nums". Note that each number in "nums" will results in 32 23 | bits in "bits". If this is not true, your function should 24 | print a message with the format: 25 | "Invalid call to numToBits! nBits is %d, nNums is %d\n", 26 | (where the first %d is nBits, and the second %d is nNums) 27 | then return without doing anything else. 28 | 29 | - Put the individual bits of each number into the "bits" array. 30 | The bits put into this array should be ordered so that the first 31 | 32 bits represent nums[0], the next 32 bits are nums[1], and so 32 | on. Within each number, the most significant bit (bit 31) should 33 | come first, and the least significant bit (bit 0) should come last. 34 | That is, bits[0] should be bit 31 of nums[0], bits[1] should 35 | be bit 30 of nums[0], and so on. 36 | 37 | 38 | 39 | 2. Compile and test your code. 40 | We have provided a main function which will print test cases 41 | and your function's answer for them. We have provided the 42 | correct output in bits_ans.txt 43 | 44 | 3. Submit as usual 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /30_sort_lines/README: -------------------------------------------------------------------------------- 1 | For this problem, you will write a program (by modifying the provided 2 | sortLines.c file) which sorts strings from input files. As we have not 3 | yet covered sorting, we have provided the code that does the acutal 4 | sorting. You can just call this function, which will sort the data. 5 | 6 | void sortData(char ** data, size_t count); 7 | 8 | The sortData function takes two arguments. The first is an array of strings. 9 | The second is the length of that array. It will re-order the elements of the 10 | array, such that they are sorted. 11 | 12 | Your task in this problem primarily centers around reading the data into 13 | the array from the input file(s), so that it can be sorted. You will also 14 | need to print the data after it is sorted, and free all of the memory you have allocated. 15 | 16 | Specifically, this program should take 0 or more command line arguments. 17 | - If no arguments (other than its own name) are provided (argc ==1), then 18 | your program should read from standard input, sort the lines of input, 19 | print the results, free memory, and exit successfully. 20 | - If 1 or more arguments are provided (argc > 1), then your program should 21 | treat each argument as an input file name. It should open that file, 22 | read all of the lines of data in it, sort the lines, print the results, 23 | free the memory, and close the file. If any errors occur, your program 24 | should print an appropriate error message and exit with EXIT_FAILURE. 25 | If no errors occur, your program should indicate its success after processing 26 | all of the files. 27 | 28 | Note that we now place *no* restriction on the length of any individual line of input. 29 | You should therefore use the getline function to read an arbitrarily long line of 30 | input, dynamically allocating space for it as needed. See the man page for getline 31 | for more details. 32 | 33 | You should make sure your program valgrinds cleanly, including no memory leaks 34 | before you submit it. As always, submit your code for grading. 35 | 36 | Hints: 37 | - Don't forget to abstract code out into smaller function. In my solution, 38 | I wrote 3 functions other than main (plus the 2 that are provided). 39 | - Don't forget to draw pictures! They are even more important 40 | as you use pointers more and more. 41 | 42 | -------------------------------------------------------------------------------- /27_matrix_input/rotateMatrix.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void rotate(char matrix[10][10]){ 5 | int range = 9; 6 | for(int i=0; i<5; i++){ 7 | for(int j=i; j<9-i; j++){ 8 | char temp = matrix[i][j]; 9 | matrix[i][j] = matrix[range-j][i]; 10 | matrix[range-j][i] = matrix[range-i][range-j]; 11 | matrix[range-i][range-j] = matrix[j][range-i]; 12 | matrix[j][range-i] = temp; 13 | } 14 | } 15 | } 16 | 17 | int main(int argc, char ** argv){ 18 | if(argc!=2){ 19 | fprintf(stderr, "Usage: Wrong amount of Arguments\n"); 20 | return EXIT_FAILURE; 21 | } 22 | 23 | FILE * f = fopen(argv[1], "r"); 24 | if(f == NULL){ 25 | fprintf(stderr,"Usage: Couldn't open file\n"); 26 | return EXIT_FAILURE; 27 | } 28 | 29 | int ch = fgetc(f); 30 | if(ch==EOF){ 31 | fprintf(stderr,"Usage: Empty File\n"); 32 | return EXIT_FAILURE; 33 | } 34 | 35 | char mat[10][10]; 36 | int row = 0; 37 | int col = 0; 38 | while(ch != EOF){ 39 | if(row > 9){ 40 | fprintf(stderr,"Usage: Higher number of rows\n"); 41 | return EXIT_FAILURE; 42 | } 43 | 44 | if(col==10){ 45 | col = 0; 46 | row++; 47 | if(ch != '\n'){ 48 | fprintf(stderr,"Usage: Missing new line at the end of the row\n"); 49 | return EXIT_FAILURE; 50 | } 51 | }else{ 52 | if(ch == '\n'){ 53 | fprintf(stderr,"Usage: Less columns than expected\n"); 54 | return EXIT_FAILURE; 55 | } 56 | mat[row][col] = ch; 57 | col ++; 58 | } 59 | ch = fgetc(f); 60 | } 61 | fclose(f); 62 | 63 | if(row<10){ 64 | fprintf(stderr,"Usage: Lower number of rows\n"); 65 | return EXIT_FAILURE; 66 | } 67 | 68 | rotate(mat); 69 | 70 | for(int i=0; i<10; i++){ 71 | for(int j=0; j<10; j++){ 72 | printf("%c",mat[i][j]); 73 | } 74 | printf("\n"); 75 | } 76 | return EXIT_SUCCESS; 77 | } 78 | -------------------------------------------------------------------------------- /c4prj2_input/input.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "input.h" 6 | 7 | size_t strToInt(char * str){ 8 | size_t len = strlen(str); 9 | size_t res = 0; 10 | size_t delta = 0; 11 | for(size_t i=0; in_cards = 0; 50 | ret_d->cards = NULL; 51 | 52 | while(str[count]!='\0'){ 53 | if(!isalpha(str[count]) && !isdigit(str[count]) && (str[count] != '?')){ 54 | count++; 55 | }else{ 56 | lstIdx = getLastIndex(str,count); 57 | if(lstIdx == -1){ 58 | return NULL; 59 | } 60 | if(str[count]=='?'){ 61 | c_name = (char *)realloc(c_name,(lstIdx-count+1)*sizeof(*c_name)); 62 | c_name = strncpy(c_name, str+count, (size_t)(lstIdx-count)); 63 | c_name[lstIdx-count] = '\0'; 64 | idx = strToInt(c_name+1); 65 | add_card = add_empty_card(ret_d); 66 | add_future_card(fc, idx, add_card); 67 | count = lstIdx; 68 | }else{ 69 | add_card_to(ret_d, card_from_letters(str[count],str[count+1])); 70 | count += 2; 71 | } 72 | g_count++; 73 | } 74 | } 75 | free(c_name); 76 | if(count<5){ 77 | fprintf(stderr, "Not enough cards"); 78 | return NULL; 79 | } 80 | return ret_d; 81 | } 82 | 83 | deck_t ** read_input(FILE * f, size_t * n_hands, future_cards_t * fc){ 84 | char *line = NULL; 85 | size_t n = 0; 86 | deck_t ** ret = NULL; 87 | while(getline(&line, &n, f)>=0){ 88 | ret = (deck_t **)realloc(ret, (*n_hands+1)*sizeof(ret)); 89 | lineToStr(line); 90 | ret[*n_hands] = hand_from_string(line, fc); 91 | (*n_hands)++; 92 | } 93 | free(line); 94 | return ret; 95 | } 96 | -------------------------------------------------------------------------------- /c4prj3_finish/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "cards.h" 6 | #include "deck.h" 7 | #include "eval.h" 8 | #include "future.h" 9 | #include "input.h" 10 | 11 | void actScore(deck_t ** hands, size_t n_hands, int * win_arr){ 12 | size_t bt_hd_idex = 0; 13 | int comp_res = 0; 14 | int tie_flag = 0; 15 | 16 | for(size_t j=1; jn_decks; i++){ 35 | free((fc->decks[i]).cards); 36 | } 37 | free(fc->decks); 38 | free(fc); 39 | } 40 | 41 | void freeAll(future_cards_t * fc, deck_t ** hands, size_t n_hands, deck_t * rem_deck, int * win_arr){ 42 | freeFutCards(fc); 43 | for(size_t i=0; i3)){ 54 | fprintf(stderr, "Wrong number of Arguments"); 55 | return EXIT_FAILURE; 56 | } 57 | 58 | int n_trails; 59 | deck_t ** hands; 60 | deck_t * rem_cards; 61 | size_t n_hands = 0; 62 | FILE * f = NULL; 63 | int * win_arr = NULL; 64 | 65 | future_cards_t * fc = (future_cards_t *)malloc(sizeof(*fc)); 66 | fc->decks = NULL; 67 | fc->n_decks = 0; 68 | 69 | if(argc == 2){ 70 | n_trails = 10000; 71 | }else{ 72 | n_trails = strToInt(argv[2]); 73 | } 74 | 75 | f = fopen(argv[1],"r"); 76 | hands = read_input(f, &n_hands, fc); 77 | rem_cards = build_remaining_deck(hands, n_hands); 78 | win_arr = (int *)realloc(win_arr, (n_hands+1)*sizeof(*win_arr)); 79 | for(size_t k=0; k 2 | #include 3 | #include 4 | #include "kv.h" 5 | #include "counts.h" 6 | #include "outname.h" 7 | 8 | 9 | counts_t * countFrFile(FILE * f, kvarray_t * kvPairs){ 10 | char * line = NULL; 11 | size_t size = 0; 12 | char * key = NULL; 13 | char * value =NULL; 14 | 15 | counts_t * res = createCounts(); 16 | 17 | if(res ==NULL){ 18 | return NULL; 19 | } 20 | while(getline(&line, &size, f)>=0){ 21 | int len = strlen(line); 22 | if(line[len-1] == '\n'){ 23 | key = realloc(key, len*sizeof(*key)); 24 | strncpy(key, line, len-1); 25 | key[len-1] = '\0'; 26 | }else{ 27 | key = realloc(key, (len+1)*sizeof(*key)); 28 | strncpy(key, line, len); 29 | key[len] = '\0'; 30 | } 31 | value = lookupValue(kvPairs, key); 32 | addCount(res, value); 33 | } 34 | 35 | free(line); 36 | free(key); 37 | 38 | return res; 39 | } 40 | counts_t * countFile(const char * filename, kvarray_t * kvPairs) { 41 | //WRITE ME 42 | FILE * f = fopen(filename, "r"); 43 | if(f==NULL){ 44 | return NULL; 45 | } 46 | counts_t * ret = countFrFile(f, kvPairs); 47 | if(ret == NULL){ 48 | return NULL; 49 | } 50 | fclose(f); 51 | return ret; 52 | } 53 | 54 | int main(int argc, char ** argv) { 55 | //WRITE ME (plus add appropriate error checking!) 56 | if(argc < 3){ 57 | fprintf(stderr, "Not enought arguments\n"); 58 | return EXIT_FAILURE; 59 | } 60 | //read the key/value pairs from the file named by argv[1] (call the result kv) 61 | kvarray_t * kvarray = readKVs(argv[1]); 62 | if(kvarray == NULL){ 63 | fprintf(stderr, "Error reading pairs"); 64 | return EXIT_FAILURE; 65 | } 66 | //count from 2 to argc (call the number you count i) 67 | for(int i=2; i : 1 42 | 43 | These should appear in the order that the name is first added, with unknown always 44 | appearing last. 45 | 46 | ***If there are no unknown values, you should not print a line for unknown. That 47 | is, you should NEVEr print 48 | : 0 49 | 50 | 51 | Finally, you should write freeCounts, which should free all the memory associated with 52 | a counts_t. 53 | 54 | We have provided a main in countsTestc which creates a counts_t (using your createCounts 55 | function), adds some names to it (using your addCount function), prints the result 56 | to stdout (using your printCounts) function, then frees the memory (using your freeCounts). 57 | 58 | Test and debug these functions before proceeding. 59 | -------------------------------------------------------------------------------- /c2prj1_cards/cards.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "cards.h" 5 | 6 | 7 | void assert_card_valid(card_t c) { 8 | assert(c.value >=2 && c.value <=14); 9 | assert(c.suit >=0 && c.suit <=3); 10 | } 11 | 12 | const char * ranking_to_string(hand_ranking_t r) { 13 | switch(r){ 14 | case STRAIGHT_FLUSH: return "STRAIGHT_FLUSH"; 15 | case FOUR_OF_A_KIND: return "FOUR_OF_A_KIND"; 16 | case FULL_HOUSE: return "FULL_HOUSE"; 17 | case FLUSH: return "FLUSH"; 18 | case STRAIGHT: return "STRAIGHT"; 19 | case THREE_OF_A_KIND: return "THREE_OF_A_KIND"; 20 | case TWO_PAIR: return "TWO_PAIR"; 21 | case PAIR: return "PAIR"; 22 | case NOTHING: return "NOTHING"; 23 | } 24 | return ""; 25 | } 26 | 27 | char value_letter(card_t c) { 28 | if(c.value>=2 && c.value < 10){ 29 | return '0'+c.value; 30 | }else{ 31 | switch(c.value){ 32 | case 10: return '0'; 33 | case 11: return 'J'; 34 | case 12: return 'Q'; 35 | case 13: return 'K'; 36 | case 14: return 'A'; 37 | } 38 | } 39 | return 'x'; 40 | } 41 | 42 | 43 | char suit_letter(card_t c) { 44 | switch(c.suit){ 45 | case SPADES: return 's'; 46 | case HEARTS: return 'h'; 47 | case DIAMONDS: return 'd'; 48 | case CLUBS: return 'c'; 49 | case NUM_SUITS: return 'x'; 50 | } 51 | return 'x'; 52 | 53 | } 54 | 55 | void print_card(card_t c) { 56 | printf("%c",value_letter(c)); 57 | printf("%c",suit_letter(c)); 58 | } 59 | 60 | card_t card_from_letters(char value_let, char suit_let) { 61 | card_t temp; 62 | if(value_let > '0' && value_let <= '9'){ 63 | temp.value = value_let - '0'; 64 | }else{ 65 | switch(value_let){ 66 | case '0': temp.value = 10; break; 67 | case 'J': temp.value = 11; break; 68 | case 'Q': temp.value = 12; break; 69 | case 'K': temp.value = 13; break; 70 | case 'A': temp.value = 14; break; 71 | default: temp.value = 20; 72 | } 73 | } 74 | switch(suit_let){ 75 | case 's': temp.suit = SPADES; break; 76 | case 'h': temp.suit = HEARTS; break; 77 | case 'd': temp.suit = DIAMONDS; break; 78 | case 'c': temp.suit = CLUBS; break; 79 | default: temp.suit = 'x'; 80 | } 81 | 82 | assert_card_valid(temp); 83 | return temp; 84 | } 85 | 86 | card_t card_from_num(unsigned c) { 87 | card_t temp; 88 | int cSuit = c/13; 89 | int cVal = c%13; 90 | switch(cSuit){ 91 | case 0: temp.suit = SPADES; break; 92 | case 1: temp.suit = HEARTS; break; 93 | case 2: temp.suit = DIAMONDS; break; 94 | case 3: temp.suit = CLUBS; break; 95 | } 96 | 97 | if(cVal >= 2){ 98 | temp.value = cVal; 99 | }else{ 100 | temp.value = cVal + 13; 101 | } 102 | return temp; 103 | } 104 | -------------------------------------------------------------------------------- /c4prj3_finish/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Mon Oct 15 19:27:35 UTC 2018 2 | Running 'make clean' to do a clean build of your project 3 | rm -rf *.o poker *~ 4 | Running 'make poker OTHERFLAGS=-O3' to build your project 5 | gcc -Wall -Werror -ggdb3 -std=gnu99 -pedantic -O3 -c -o cards.o cards.c 6 | gcc -Wall -Werror -ggdb3 -std=gnu99 -pedantic -O3 -c -o deck.o deck.c 7 | gcc -Wall -Werror -ggdb3 -std=gnu99 -pedantic -O3 -c -o eval.o eval.c 8 | gcc -Wall -Werror -ggdb3 -std=gnu99 -pedantic -O3 -c -o future.o future.c 9 | gcc -Wall -Werror -ggdb3 -std=gnu99 -pedantic -O3 -c -o input.o input.c 10 | gcc -Wall -Werror -ggdb3 -std=gnu99 -pedantic -O3 -c -o main.o main.c 11 | gcc -o poker -Wall -Werror -ggdb3 -std=gnu99 -pedantic -O3 cards.o deck.o eval.o future.o input.o main.o 12 | - Starting with some Texas Hold'em hands 13 | Running a simulation with 20000 draws for 2 hands... 14 | Hand 0 was close enough to our answer 15 | Hand 1 was close enough to our answer 16 | Test case passed! 17 | Running a simulation with 25000 draws for 3 hands... 18 | Hand 0 was close enough to our answer 19 | Hand 1 was close enough to our answer 20 | Hand 2 was close enough to our answer 21 | Test case passed! 22 | Running a simulation with 25000 draws for 3 hands... 23 | Hand 0 was close enough to our answer 24 | Hand 1 was close enough to our answer 25 | Hand 2 was close enough to our answer 26 | Test case passed! 27 | Running a simulation with 25000 draws for 2 hands... 28 | Hand 0 was close enough to our answer 29 | Hand 1 was close enough to our answer 30 | Test case passed! 31 | Running a simulation with 80000 draws for 4 hands... 32 | Hand 0 was close enough to our answer 33 | Hand 1 was close enough to our answer 34 | Hand 2 was close enough to our answer 35 | Hand 3 was close enough to our answer 36 | Test case passed! 37 | Running a simulation with 30000 draws for 2 hands... 38 | Hand 0 was close enough to our answer 39 | Hand 1 was close enough to our answer 40 | Test case passed! 41 | - Next, few Seven Card Stud hands 42 | Running a simulation with 30000 draws for 2 hands... 43 | Hand 0 was close enough to our answer 44 | Hand 1 was close enough to our answer 45 | Test case passed! 46 | Running a simulation with 40000 draws for 3 hands... 47 | Hand 0 was close enough to our answer 48 | Hand 1 was close enough to our answer 49 | Hand 2 was close enough to our answer 50 | Test case passed! 51 | - Then one from a completely made up poker variant 52 | Running a simulation with 100000 draws for 6 hands... 53 | Hand 0 was close enough to our answer 54 | Hand 1 was close enough to our answer 55 | Hand 2 was close enough to our answer 56 | Hand 3 was close enough to our answer 57 | Hand 4 was close enough to our answer 58 | Hand 5 was close enough to our answer 59 | Test case passed! 60 | 61 | Overall Grade: A 62 | -------------------------------------------------------------------------------- /02_code1/grade.txt: -------------------------------------------------------------------------------- 1 | Grading at Fri Oct 12 02:59:32 UTC 2018 2 | Checking code1.c for legal syntax 3 | Checking for int max (int num1, int num2) 4 | Found on line 3, column 1 5 | Checking for int main(void) 6 | Found on line 10, column 1 7 | Trying to run the code.. 8 | Your file matched the expected output 9 | Removing your main() and replacing it with our own to run more tests... 10 | Testing max(-999, -2147483648) ... Correct 11 | Testing max(-999, 123) ... Correct 12 | Testing max(-999, 567) ... Correct 13 | Testing max(-999, 891) ... Correct 14 | Testing max(-999, 0) ... Correct 15 | Testing max(-999, 1) ... Correct 16 | Testing max(-999, -999) ... Correct 17 | Testing max(-999, 123123123) ... Correct 18 | Testing max(-87, -2147483648) ... Correct 19 | Testing max(-87, 123) ... Correct 20 | Testing max(-87, 567) ... Correct 21 | Testing max(-87, 891) ... Correct 22 | Testing max(-87, 0) ... Correct 23 | Testing max(-87, 1) ... Correct 24 | Testing max(-87, -999) ... Correct 25 | Testing max(-87, 123123123) ... Correct 26 | Testing max(0, -2147483648) ... Correct 27 | Testing max(0, 123) ... Correct 28 | Testing max(0, 567) ... Correct 29 | Testing max(0, 891) ... Correct 30 | Testing max(0, 0) ... Correct 31 | Testing max(0, 1) ... Correct 32 | Testing max(0, -999) ... Correct 33 | Testing max(0, 123123123) ... Correct 34 | Testing max(1, -2147483648) ... Correct 35 | Testing max(1, 123) ... Correct 36 | Testing max(1, 567) ... Correct 37 | Testing max(1, 891) ... Correct 38 | Testing max(1, 0) ... Correct 39 | Testing max(1, 1) ... Correct 40 | Testing max(1, -999) ... Correct 41 | Testing max(1, 123123123) ... Correct 42 | Testing max(240, -2147483648) ... Correct 43 | Testing max(240, 123) ... Correct 44 | Testing max(240, 567) ... Correct 45 | Testing max(240, 891) ... Correct 46 | Testing max(240, 0) ... Correct 47 | Testing max(240, 1) ... Correct 48 | Testing max(240, -999) ... Correct 49 | Testing max(240, 123123123) ... Correct 50 | Testing max(345, -2147483648) ... Correct 51 | Testing max(345, 123) ... Correct 52 | Testing max(345, 567) ... Correct 53 | Testing max(345, 891) ... Correct 54 | Testing max(345, 0) ... Correct 55 | Testing max(345, 1) ... Correct 56 | Testing max(345, -999) ... Correct 57 | Testing max(345, 123123123) ... Correct 58 | Testing max(999999, -2147483648) ... Correct 59 | Testing max(999999, 123) ... Correct 60 | Testing max(999999, 567) ... Correct 61 | Testing max(999999, 891) ... Correct 62 | Testing max(999999, 0) ... Correct 63 | Testing max(999999, 1) ... Correct 64 | Testing max(999999, -999) ... Correct 65 | Testing max(999999, 123123123) ... Correct 66 | Testing max(2147483647, -2147483648) ... Correct 67 | Testing max(2147483647, 123) ... Correct 68 | Testing max(2147483647, 567) ... Correct 69 | Testing max(2147483647, 891) ... Correct 70 | Testing max(2147483647, 0) ... Correct 71 | Testing max(2147483647, 1) ... Correct 72 | Testing max(2147483647, -999) ... Correct 73 | Testing max(2147483647, 123123123) ... Correct 74 | 75 | Overall Grade: A 76 | -------------------------------------------------------------------------------- /10_gdb/README: -------------------------------------------------------------------------------- 1 | For this assignment, you will be practicing with the basics 2 | of gdb. You will want to use gdb extensively during the rest 3 | of the semester, as it is an incredibly useful tool to gather 4 | information during the debugging process. For now, we 5 | are just going to get started with some basic commands. 6 | Be sure you have done the readings and watched 7 | the video on gdb. 8 | 9 | Enclosed, you will find game.c and the compiled 10 | binary game, for the most boring guessing game 11 | ever. In the first round, the program thinks 12 | of a secret number (it is the same every single time), 13 | and asks you to guess it. You get exactly one try. 14 | Note that it thinks of this number by calling 15 | getSecretNumber, which is not included in the source. 16 | 17 | If you get that right, in the second round, 18 | it thinks of another number. It does this by repeatedly 19 | calling getOtherSN (also not shown in the source) and 20 | passing in different numbers. It combines these results 21 | together, and does some math to combine the results into 22 | "total". Afterwards, it asks you for your guess, 23 | and again, you have one chance. 24 | 25 | Before you proceed, try to "play" the game once by running: 26 | 27 | ./game 28 | 29 | 30 | For example, I ran it and guessed 4: 31 | $ ./game 32 | I'm thinking of a number... 33 | What number do you guess? 34 | 4 35 | I'm sorry, that is not right. You lose 36 | 37 | It would be pretty boring to play this game 38 | until you actually guess the right number and win, 39 | but fortunately, that isn't the point. The 40 | point is to practice with gdb. 41 | 42 | In emacs, do 43 | 44 | ESC-x gdb 45 | 46 | Emacs will prompt you for how to run gdb (the default should be fine), 47 | and then give you the gdb prompt. 48 | Use the "start" commmand to begin execution, then use "next" 49 | and "print" to find the secret number for round 1. 50 | When the program prompts you for this number, you should be able 51 | to guess the right one from the information you gathered. 52 | 53 | For round 2, you do not want to step through 5000+ iterations of the 54 | loop, so set a breakpoint after the loop, continue execution until you 55 | reach it, and the print out the variable "total". Now you should 56 | be able to win round 2 instantly as well! 57 | 58 | Once you have found the two secret numbers, create a file called input.txt 59 | and place them in that file, one per line (round 1's secret number 60 | on the first line, and round 2's on the second line). 61 | 62 | You should be able to run 63 | 64 | ./game < input.txt 65 | 66 | and "win" automatically. That is, you should see this output (without 67 | having to type anything else): 68 | 69 | $ ./game < input.txt 70 | I'm thinking of a number... 71 | What number do you guess? 72 | Correct! You win round1! 73 | Ok, time for round 2. I have another secret number. 74 | Your guess: 75 | You win round 2 also! 76 | 77 | 78 | When you finish, add input.txt to git, then commit, push, and grade. 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /06_rect/README: -------------------------------------------------------------------------------- 1 | For this problem, we will be writing a function which takes 2 | two rectangles, determines the region in which they overlap 3 | (which is also a rectangle), and returns that region. 4 | 5 | Before proceeding, think about what the corner case(s) [no pun intended!] 6 | in this problem might be. 7 | 8 | 1. Open the provided file called "rectangle.c" 9 | 10 | 2. In the "rectangle.c" file, define a struct for rectangles 11 | which has 4 fields: x, y, width, and height. Each of these 12 | fields should be an int. Use typedef so that the typename 13 | "rectangle" refers to your struct. 14 | 15 | 3. One corner we might have to deal with is if the rectangle's 16 | representation is non-standard: if the width or height are 17 | negative. One way to deal with inputs that come in non-standard 18 | formats is to "canonicalize" them---convert them to the standard 19 | (or "canonical") representation. First, write the function 20 | 21 | rectangle canonicalize(rectangle r); 22 | 23 | which takes a rectangle, and "fixes" its representation 24 | by ensuring that the width and height are non-negative (and 25 | appropriately adjusting the x and/or y co-ordinate). That is, 26 | if your canonicalize function were passed a rectangle with 27 | x=3, y=2, width=-2, height=4 28 | then it should return a rectangle with 29 | x=1, y=2, width=2, height=4 30 | as these both describe the same rectangle, but the later is 31 | in a canonical representation. 32 | 33 | It may be a good idea to stop and test this function 34 | before proceeding. Compile and run your code. 35 | The main function we have provided should be useful, 36 | as it canonicalizes the rectangles it prints. 37 | 38 | 4. Now, write the function 39 | rectangle intersection(rectangle r1, rectangle r2) 40 | which takes two rectangles (r1, and r2), and returns 41 | the rectangle representing the intersection of the two. 42 | 43 | Note that there is a corner case where the correct answer 44 | is "no intersection". We have not learned how to represent 45 | "no such thing" yet, but we will consider a rectangle with 46 | both width and height equal to 0 to mean "no such rectangle". 47 | 48 | We will consider a rectangle to have one (but not the other) 49 | of width or height equal to 0 to be an appropriate answer 50 | when rectangles share an edge but do not overlap. For example, 51 | x=0,y=0,width=1, height=1 52 | and 53 | x=-1,y=1,width=3,height=2 54 | Should result in the "rectangle" 55 | x=0,y=1,width=1,height=0 56 | 5. We have provided a main function which tests your code, 57 | as well as correct output (rectangle_ans.txt) to diff against. 58 | 59 | 6. Submit your code 60 | 61 | Hint: 62 | Do Step 1 (work an example yourself) four or five times. 63 | Draw a variety of different ways that rectangles can overlap. 64 | Use these to help you think abou the general algorithm for how 65 | to determine their overlapping region. 66 | -------------------------------------------------------------------------------- /09_testing2/README: -------------------------------------------------------------------------------- 1 | For this assignment, you will continue working on your blackbox testing 2 | skills. However, this time, you will test a slightly more complex program 3 | with more broken implementations. 4 | 5 | You can find the correct implementation of the program at 6 | 7 | /usr/local/l2p/match5/correct-match5 8 | 9 | This program determines who wins a very simple "card game". This "game" 10 | is played with 5 "cards" per player and 2 players. A "card" in this 11 | game is an ASCII character (so 'x' 'a' '!' '7' '$' etc are all valid cards). 12 | Each player has exactly 5 cards, and the player with the most matching 13 | cards wins. That is, 5 of a kind beats 4 of a kind, which bests 3 of a kind, 14 | which beats a pair, which beats having no matching cards. If both 15 | players have the same number of matching cards (e.g., both have 3 of a kind), 16 | the hand is a tie. There are no tie breakers (so one player has 17 | 3 of a kind and the other has 3 of a kind + a pair, the pair does not matter). 18 | The values of the cards don't matter (so three 'a's and three 'b's both tie). 19 | 20 | If you run the correct implementation, you can see the correct behavior: 21 | 22 | As some examples: 23 | 24 | $ /usr/local/l2p/match5/correct-match5 aaaaa bbbbb 25 | Both hands tie: each has five of a kind 26 | 27 | $ /usr/local/l2p/match5/correct-match5 aaaaa bbbbc 28 | Hand 1's five of a kind beats Hand 2's four of a kind 29 | 30 | $ /usr/local/l2p/match5/correct-match5 aaabb bbbbc 31 | Hand 1's three of a kind loses to Hand 2's four of a kind 32 | 33 | If you look in /usr/local/l2p/match5, you will see that there are 296 broken 34 | implementations. Note that you do NOT need to come up with 296 test cases---you 35 | may have one test case which shows that several of these implementations 36 | are broken. 37 | 38 | Furthermore, to help make this testing managable for you, we have provided 39 | run_all.sh, which will read test cases from a file you create called tests.txt, 40 | and run them against all broken implementations. In particular, each line 41 | of tests.txt should be the command line arguments to one invocation of the 42 | program under test. So if you wanted to test the program with the three 43 | examples shown above, you would write the following in tests.txt 44 | 45 | aaaaa bbbbb 46 | aaaaa bbbbc 47 | aaabb bbbbc 48 | 49 | and then each broken program would be run three times, and have its behavior 50 | compared to the correct implementation. If ANY test case in tests.txt identifies 51 | a problem with a particular broken implementation, your test suite has 52 | succeeded for that particular implementation. You need to develop 53 | your test suite so that it identifies the problems with all broken implementations. 54 | 55 | 56 | Lastly, I'll note that each of these broken implementations arises from 57 | making small changes in the correct implementation which could represent 58 | reasonable mistakes in programming (this is called "mutation testing" by 59 | the way). None of these require finding 60 | an obscure "magic bullet" input---they can all be found with a reasonble, 61 | comprehensive test suite. 62 | 63 | You will submit tests.txt for this assignment. 64 | 65 | -------------------------------------------------------------------------------- /32_kvs/kv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "kv.h" 5 | 6 | int findEqIdx(char * line){ 7 | char c = *line; 8 | int count = 0; 9 | while(c!='='){ 10 | count++; 11 | c = *(line+count); 12 | if(c=='='){ 13 | return count; 14 | } 15 | } 16 | return -1; 17 | } 18 | 19 | 20 | char * getKey(char * line){ 21 | int eq_idx = findEqIdx(line); 22 | if(eq_idx == -1){ 23 | return NULL; 24 | } 25 | char * key = malloc((eq_idx+1)*sizeof(*key)); 26 | strncpy(key, line, eq_idx); 27 | key[eq_idx] = '\0'; 28 | return key; 29 | } 30 | 31 | char * getValue(char * line){ 32 | int eq_idx = findEqIdx(line); 33 | if(eq_idx == -1){ 34 | return NULL; 35 | } 36 | char * value = NULL; 37 | size_t len = strlen(line); 38 | if(line[len-1] != '\n'){ 39 | value = realloc(value, ((int)len - eq_idx)*sizeof(*value)); 40 | strcpy(value,(line+eq_idx+1)); 41 | value[(int)len-eq_idx-1] = '\0'; 42 | }else{ 43 | value = realloc(value, ((int)len - eq_idx)*sizeof(*value)); 44 | strncpy(value,(line+eq_idx+1),(int)len-eq_idx-1); 45 | value[(int)len-eq_idx-2] = '\0'; 46 | } 47 | return value; 48 | } 49 | 50 | kvpair_t * parseKV(char * line){ 51 | kvpair_t * pair = malloc(sizeof(*pair)); 52 | pair -> key = getKey(line); 53 | if(pair->key == NULL){ 54 | return NULL; 55 | } 56 | pair -> value = getValue(line); 57 | if(pair->value == NULL){ 58 | return NULL; 59 | } 60 | return pair; 61 | } 62 | 63 | kvarray_t * readKVs(const char * fname) { 64 | //WRITE ME 65 | FILE * f = fopen(fname, "r"); 66 | if(f==NULL){ 67 | return NULL; 68 | } 69 | 70 | kvarray_t * arr = malloc(sizeof(*arr)); 71 | arr -> array = NULL; 72 | char * line = NULL; 73 | size_t size = 0; 74 | size_t sz = 0; 75 | while((getline(&line, &size, f))>=0){ 76 | arr -> array = realloc(arr->array, (sz+1)*sizeof(arr->array)); 77 | arr -> array[sz] = parseKV(line); 78 | if(arr -> array[sz] == NULL){ 79 | return NULL; 80 | } 81 | sz++; 82 | } 83 | free(line); 84 | arr -> sz = sz; 85 | fclose(f); 86 | return arr; 87 | } 88 | 89 | void freeKVs(kvarray_t * pairs) { 90 | //WRITE ME 91 | int sz = pairs -> sz; 92 | for(int i=0; i array[i])-> key); 94 | free((pairs -> array[i])-> value); 95 | free(pairs -> array[i]); 96 | } 97 | free(pairs->array); 98 | free(pairs); 99 | } 100 | 101 | void printKVs(kvarray_t * pairs) { 102 | //WRITE ME 103 | size_t sz = pairs -> sz; 104 | kvpair_t * temp_kvp; 105 | for(size_t i=0; iarray[i]; 107 | printf("key = '%s' value = '%s'\n", temp_kvp->key, temp_kvp->value); 108 | } 109 | } 110 | 111 | char * lookupValue(kvarray_t * pairs, const char * key) { 112 | //WRITE ME 113 | size_t sz = pairs->sz; 114 | for(size_t i=0; iarray[i])->key)==0){ 116 | return (pairs->array[i])->value; 117 | } 118 | } 119 | return NULL; 120 | } 121 | -------------------------------------------------------------------------------- /c3prj1_deck/deck.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "deck.h" 5 | void print_hand(deck_t * hand){ 6 | card_t ** ptr = hand->cards; 7 | for(int i=0; i<(hand->n_cards); i++){ 8 | print_card(**ptr); 9 | printf("%s"," "); 10 | ptr++; 11 | } 12 | } 13 | 14 | int deck_contains(deck_t * d, card_t c) { 15 | card_t ** ptr = d->cards; 16 | for(int i=0; i<(d->n_cards); i++){ 17 | if(suit_letter(**ptr)== suit_letter(c) && value_letter(**ptr)==value_letter(c)){ 18 | return 1; 19 | } 20 | ptr++; 21 | } 22 | return 0; 23 | } 24 | 25 | void cardPtr_swap(card_t ** ptr1, card_t ** ptr2){ 26 | card_t * temp = *ptr1; 27 | *ptr1 = *ptr2; 28 | *ptr2 = temp; 29 | } 30 | 31 | void shuffle(deck_t * d){ 32 | card_t ** ptr = d->cards; 33 | int size = (int)(d->n_cards); 34 | for(int i=0; icards; 42 | deck_t temp_deck; 43 | temp_deck.cards = d->cards; 44 | for(int i=0; i<(d->n_cards); i++){ 45 | card_t temp_card = **ptr; 46 | assert_card_valid(temp_card); 47 | if(i>0){ 48 | temp_deck.n_cards = (size_t)i; 49 | assert(!deck_contains(&temp_deck, temp_card)); 50 | } 51 | ptr++; 52 | } 53 | } 54 | 55 | void add_card_to(deck_t * deck, card_t c){ 56 | deck->n_cards++; 57 | deck->cards = realloc(deck->cards,(deck->n_cards)*sizeof(*(deck->cards))); 58 | deck->cards[deck->n_cards-1] = NULL; 59 | deck->cards[deck->n_cards-1] = realloc(deck->cards[deck->n_cards-1], sizeof(*(deck->cards[deck->n_cards-1]))); 60 | deck->cards[deck->n_cards-1]->suit = c.suit; 61 | deck->cards[deck->n_cards-1]->value = c.value; 62 | } 63 | 64 | card_t * add_empty_card(deck_t * deck){ 65 | card_t * temp = malloc(sizeof(*temp)); 66 | temp->suit = 0; 67 | temp->value = 0; 68 | deck->n_cards++; 69 | deck->cards = realloc(deck->cards, (deck->n_cards)*sizeof(*(deck->cards))); 70 | deck->cards[deck->n_cards-1] = temp; 71 | return temp; 72 | } 73 | 74 | deck_t * make_deck_exclude(deck_t * excluded_cards){ 75 | card_t temp; 76 | deck_t * res = malloc(sizeof(*res)); 77 | res->n_cards = 0; 78 | res->cards = NULL; 79 | 80 | int cond = 0; 81 | for(unsigned i=0; i<52; i++){ 82 | temp = card_from_num(i); 83 | cond = deck_contains(excluded_cards, temp); 84 | if(cond==0){ 85 | add_card_to(res, temp); 86 | } 87 | } 88 | return res; 89 | } 90 | 91 | deck_t * build_remaining_deck(deck_t ** hands, size_t n_hands){ 92 | deck_t * temp; 93 | deck_t * no_ret_d = malloc(sizeof(*no_ret_d)); 94 | deck_t * ret_d; 95 | no_ret_d->n_cards = 0; 96 | no_ret_d->cards = NULL; 97 | card_t * temp_c; 98 | for(size_t i=0; in_cards; j++){ 101 | temp_c = temp->cards[j]; 102 | if(temp_c->value != 0){ 103 | if(deck_contains(no_ret_d, *temp_c)==0){ 104 | add_card_to(no_ret_d, *temp_c); 105 | } 106 | } 107 | } 108 | } 109 | ret_d = make_deck_exclude(no_ret_d); 110 | free_deck(no_ret_d); 111 | return ret_d; 112 | } 113 | 114 | void free_deck(deck_t * deck){ 115 | for(size_t i=0; in_cards; i++){ 116 | free(deck->cards[i]); 117 | } 118 | free(deck->cards); 119 | free(deck); 120 | } 121 | -------------------------------------------------------------------------------- /31_minesweeper/README: -------------------------------------------------------------------------------- 1 | 2 | ********************************************************************* 3 | ** REMINDER: your programs MUST valgrind cleanly for full credit! ** 4 | ********************************************************************* 5 | 6 | For this problem, you will be completing a partially written 7 | minesweeper game. This game will be played on a text interface 8 | (not a GUI---we haven't learned anything about those). 9 | 10 | If you are not familiar with the game of minesweeper, you might 11 | take a minute to read up about it on the internet, but you don't 12 | need much game expertise to do this assignment. 13 | 14 | I have provided code for an almost working minesweeper, except 15 | that I have deleted the code for 4 functions: 16 | 17 | board_t * makeBoard(int w, int h, int numMines) 18 | int countMines(board_t * b, int x, int y) 19 | int checkWin(board_t * b) 20 | void freeBoard(board_t * b) 21 | 22 | 23 | Your job is to implement each of these functions (which all have a 24 | //WRITE ME comment to make them easy to find). A brief description 25 | of each follows: 26 | 27 | 28 | - makeBoard: this function should malloc and initialize a board_t 29 | representing the board. The parameters specify the width 30 | and height of the board, as well as the number of mines. 31 | You will also need to call malloc (multiple times) 32 | to allocate space for the 2D array "board". 33 | This function should fill in all squares on the board with 34 | UNKNOWN, then call addRandomMine an appropriate number of times 35 | (i.e., numMines) to "randomly" place mines on the board. 36 | Note that the fields of your board_t must be initailzed before 37 | you call addRandomMine. 38 | Also note that the mine generation is pseudo random and will not 39 | change if you re-run the program multiple times with the same 40 | parameters. 41 | 42 | Note that the layout of b->board should be such that it is indexed 43 | b->board[y][x] 44 | where y is between 0 and the height and x is between 0 and the width. 45 | 46 | - countMines: this funciton takes a board_t, and an (x,y) coordinate. 47 | It should count the mines in the 8 squares around that (x,y) 48 | coordinate, and return that count. Note that a mine may be 49 | indicated by a square on the board either being HAS_MINE or 50 | KNOWN_MINE. You can use the IS_MINE macro to test both cases: 51 | IS_MINE(b->board[ny][nx]) 52 | (where b is the board_t, and (nx,ny) are the coordinates you 53 | want to check). Be careful not to go out of bounds of the array. 54 | 55 | - checkWin: this funciton takes a board_t and see if the game has 56 | been won. The game is won when no squares are UNKNOWN. 57 | 58 | - freeBoard: This function takes a board_t and frees all memory 59 | associated with it (including the array inside of it). That is, 60 | freeBoard should undo all the allocations made by a call to makeBoard. 61 | 62 | Note: You should NOT change any of the other provided functions! 63 | 64 | 65 | Once you have these all working, you should have a playable game of 66 | minesweeper. Note that there are a few differences in game play 67 | from the "standard" game: 68 | 69 | - You select a square by entering its x (column) and y (row) coordinate. 70 | The x coordinates are listed across the top and the y are listed 71 | down the left side to reduce counting. 72 | 73 | - The game will automatically figure out the "obvious" squares: 74 | both mines and non-mined spaces. It will reveal these too you 75 | as soon as it considers them trivial to figure out. 76 | 77 | - You cannot manually mark a square that you suspect has a mine 78 | 79 | Once your code is complete, submit minesweeper.c -------------------------------------------------------------------------------- /30_sort_lines/sortLines.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | //This function is used to figure out the ordering 7 | //of the strings in qsort. You do not need 8 | //to modify it. 9 | int stringOrder(const void * vp1, const void * vp2) { 10 | const char * const * p1 = vp1; 11 | const char * const * p2 = vp2; 12 | return strcmp(*p1, *p2); 13 | } 14 | //This function will sort and print data (whose length is count). 15 | void sortData(char ** data, size_t count) { 16 | qsort(data, count, sizeof(char *), stringOrder); 17 | } 18 | 19 | char ** readFromStd(char ** lines, size_t * count){ 20 | char * curr = NULL; 21 | size_t sz = 0; 22 | 23 | while(getline(&curr, &sz, stdin)>=0){ 24 | if (curr==NULL){ 25 | return NULL; 26 | } 27 | lines = realloc(lines, (*count+1)*sizeof(*lines)); 28 | if(lines==NULL){ 29 | return NULL; 30 | } 31 | lines[*count] = curr; 32 | (*count)++; 33 | curr = NULL; 34 | } 35 | 36 | if(*count == 0){ 37 | return NULL; 38 | } 39 | free(curr); 40 | return lines; 41 | } 42 | 43 | char ** readFromFiles(char ** lines, char * filename, size_t * count){ 44 | lines = NULL; 45 | char * curr = NULL; 46 | size_t sz = 0; 47 | 48 | FILE * f = fopen(filename, "r"); 49 | if(f==NULL){ 50 | return NULL; 51 | } 52 | while(getline(&curr, &sz, f)>=0){ 53 | if (curr==NULL){ 54 | return NULL; 55 | } 56 | lines = realloc(lines, (*count+1)*sizeof(*lines)); 57 | if(lines==NULL){ 58 | return NULL; 59 | } 60 | lines[*count] = curr; 61 | (*count)++; 62 | curr = NULL; 63 | } 64 | free(curr); 65 | int close = fclose(f); 66 | if(close != 0){ 67 | return NULL; 68 | } 69 | return lines; 70 | } 71 | 72 | int printArray(char ** lines, size_t count){ 73 | if(count>1){ 74 | sortData(lines, count); 75 | }else{ 76 | return EXIT_FAILURE; 77 | } 78 | for(size_t i=0; i 1){ 104 | for(int i=1; i