UWA Logo Computer Science & Software Engineering
C Programming (CITS1210) - Tutorial 2
   Faculty Home  |  CSSE Home  |  csentry  |  CITS1210  |  help1210

Tutorial 2: Arrays

1. Write a function that counts and displays the distribution of (assumed to be single-digit positive integer) command-line arguments supplied to the program. For example:

csse2100% ./distribution 1 2 3 1 1 1 1 3 7
The distribution of the numbers is:
1: 5
2: 1
3: 2
4: 0
5: 0
6: 0
7: 1
8: 0
9: 0

Your function should accept two arguments: an integer array of numbers, and an integer representing the number of values in the array.

2. Write a function to test whether one string is a substring of another string. For example:

csse2100% ./strstr hello el
Was el found in hello? Yes

csse2100% ./strstr hello dog
Was dog found in hello? No

csse2100% ./strstr abababcd ababc
Was ababc found in abababcd? Yes

csse2100% ./strstr abababcd ababe
Was ababe found in abababcd? No

Your function should accept two arguments: a base string to search through (the haystack), and a target string to search for (the needle). Your function should return a Boolean to indicate whether the needle string was found in the haystack string.

Top of Page CRICOS Provider Code: 00126G Valid HTML 4.01 Transitional