pointers and arrays!

so, im understanding pointers. Although i do hate them ha ha so confusing. I was struggling with these two and i could use some help:

# Write the function

void mergeArrays(int* a1, int size1, int* a2, int size2, int* a3);

This function has 5 parameters: two arrays (a1 and a2) and their sizes (size1 and size2), and the third array (a3). The function merges a1 and a2 into a3 -- all elements in a1, then all elements in a2. Thus, a3 essentially becomes the concatenation of a1 and a2. You may assume that a3 is allocated with enough space to hold the concatenation.

IMPORTANT SPECIFICATION: Do NOT use the array index notation ([]) nowhere in the function; use the pointer notation (*) only. You will receive 0 points if you use the [] notation.


#

Write the function

int find_index(char *str, char c);

This function returns the index of the first/left-most occurrence of the parameter char c in a cstring str. The function returns -1 if c does not occur in str. Write the function using a pointer notation (*) ONLY in traversing the cstring.

NOTE: The parameter str is a pointer to a cstring (not a string class object) that is terminated with a null character '\0'. Also the index returned should be 0-based, for example, if the function is called where str points to a cstring "abc" and c is 'b', the function returns 1, whereas if str points to "abc" and c is 'd', the function returns -1.

IMPORTANT SPECIFICATION: Do NOT use the array index notation ([]) nowhere in the function; use the pointer notation (*) only. You will receive 0 points if you use the [] notation.
Here is a hint:

1
2
3
4
5
6
// Given:
int array[ 10 ];

// The following lines of code both assign the value 5 to index 2:
array[ 2 ] = 5;
*( array + 2 ) = 5;


Your assignment seems to imply you should use the latter syntax.
Topic archived. No new replies allowed.