Question: I'm having difficulty with pointers and could use an example of the following function: (The restrictions that are making this so hard for me are

I'm having difficulty with pointers and could use an example of the following function: (The restrictions that are making this so hard for me are in bold after the function description)

  • void read_string(char *str, const int *max_len, int *len) - does the following:
    1. Reads a line of characters from the console and stores them in the array pointed to by str followed by the null character '\0'.
    2. Sets *len to the number of characters read.
    3. max_len points to the size of the array str.
    4. Read only up to *max_len - 1 characters from the console.
    5. Hint: use cin.get() to read a single character at a time, and stop when you reach a ' ' newline character.
    6. Functions can only take pointers as arguments.
    7. The array subscript operator [] may not be used to access or modify the contents of an array.
    8. Reference variables may not be used.
    9. With the exception of main, all functions must be void functions.
    10. The C++ string class can not be used to store plaintext, keywords, or ciphertext. Instead use arrays of characters.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!