CSC270 Survey of Programming Languages In Class
C Programming Exercises
Exercise | Description | Comment |
Practice passing by reference. here is the working exercise: | ||
Create a Function Using a Static Variable | Create a program that has a main method and a function to calculate a price. The list price always gets a 5% discount. Every third price requested gets an extra 5% discount. | |
Practice Reference pass and Arrays | directions to print an array of dice and return both the sum and the highest number - have to use a reference (because we did not learn about structures) | |
Array size | Just look at array size and how the function loses the size here is the working exercise | |
See demo programs for dynamic arrays and make changes Here is the DynArrayDemo.c working. Note that while the array variable a holds an address, the cell variable a[4] does not hold an address. Therefore, when you pass the array variable to scanf, just pass a, but when you pass the cell variable a[index] to scanf, you must pass &a[index]. |
||
See demo programs for strings and make changes wget http://home.adelphi.edu/~pe16132/csc270/note/StringSampleCode/StringFunctions1.c wget http://home.adelphi.edu/~pe16132/csc270/note/StringSampleCode/StringFunctions2.c |
||
Make requested changes inside stringFunctions3.c wget http://home.adelphi.edu/~pe16132/csc270/note/StringSampleCode/stringFunctions3.c |
||
avggrade.c |
wget http://home.adelphi.edu/~pe16132/csc270/note/SampleCode/avggrade.c Make these changes:
|
|
bitwise.c |
wget http://home.adelphi.edu/~pe16132/csc270/note/SampleCode/bitwise.c Trace this before running it and predict the numbers that will print Make these changes: |
|
pointertrace.txt |
wget http://home.adelphi.edu/~pe16132/csc270/note/SampleCode/pointertrace.c Answer - run and compile: pointertrace.c |
|
very simple read and write text
|
wget http://home.adelphi.edu/~pe16132/csc270/note/SampleCode/simplewriter.c
|
|
simple read a text file and write a binary file
|
wget http://home.adelphi.edu/~pe16132/csc270/note/SampleCode/simplewriterb.c
|
|
simple read a binary file and write a new binary file
|
wget http://home.adelphi.edu/~pe16132/csc270/note/SampleCode/simplereaderb.c
|
|
update a binary file
|
wget http://home.adelphi.edu/~pe16132/csc270/note/SampleCode/simpleupdaterb.c
|
|
text file read and write
|
text file read and write wget http://home.adelphi.edu/~pe16132/csc270/note/SampleCode/tolower2Working.c --- sample input file: wget http://home.adelphi.edu/~pe16132/csc270/note/SampleCode/input1.txt Non-working exercise: wget http://home.adelphi.edu/~pe16132/csc270/note/SampleCode/tolower2.c |
|
Read a text file / write a binary and then reverse |
wget http://home.adelphi.edu/~pe16132/csc270/note/SampleCode/writerecWorking.c
wget http://home.adelphi.edu/~pe16132/csc270/note/SampleCode/readrecWorking.c
wget http://home.adelphi.edu/~pe16132/csc270/note/SampleCode/rec_bin.txt
wget http://home.adelphi.edu/~pe16132/csc270/note/SampleCode/rec_text.txt
Non-Working versions of the binary read and write for practice:
|
|
Make file demo makefile including one c and h file only |
wget http://home.adelphi.edu/~pe16132/csc270/note/SampleCode/simplemake.c wget http://home.adelphi.edu/~pe16132/csc270/note/SampleCode/simplemake.h wget http://home.adelphi.edu/~pe16132/csc270/note/SampleCode/Makefile |