Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need the following function to read a users name into the destination Function:

ID: 3541740 • Letter: N

Question

Need the following function to read a users name into the destination


Function:

void read(char* destination, int maxChars)


Purpose:

Read a string of characters entered by the user at the keyboard with a length no longer than maxChars (including the null character at the end of the C string) into an address specified by destination The user should be able to type a space or tab as part of the string.


The getline() method of the istream class in the header file <iostream> can be used to read a string that contains spaces or tabs into an array of char.

Explanation / Answer


void read(char* destination, int maxChars)

{


int i = 0;


char temp[10000];


cin.getline(temp,1000);

while(i<maxChars)


{


destination[i] = temp[i];


i++;


}


destination[i] = '';


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote