-
Notifications
You must be signed in to change notification settings - Fork 14
Description
Hi @AndrewLaing,
In the file named ex08_28.c, the strcat2() function was implemented incorrectly. This error may have been skipped because of the wrong call on line fifty-third where you want to run the strcat2() function.
CHowToProgramExercises/Chapter8/ex08_28.c
Line 53 in b2651cf
| printf("Value returned = '%s'\n", strcat1(s4, "ts") ); |
I didn't fork the project thinking that there would not be much change on the project. So instead of creating a pull request, I opened a new issue. You can edit the strcat2() function as follows:
Click to see the recommended source code.
/**
* @brief It is a function that appends the "source" character array to the end of the "destination" character array.
* @param[in] destination Is the character array to which the character array "source" will be appended.
* @param[in] source "destination" is the character arary to be appended to the end of the character array.
* @param[out] result It is the character array that will be sent to the client after the insertion is made.
*/
char *strcat2( char* destination, const char *source )
{
if( ( destination == NULL ) && ( source == NULL ) )
return NULL;
char *result = destination;
while( *result++ != '\0' );
while( *source != '\0' )
*result++ = *source++;
*result='\0';
return result;
}The only difference is that the while( *result++ != '\0' ); pointer arithmetic is applied to point to the last element (last element of destination array) of the destination array before appending to the first array (destination).
Thank you for your work on behalf of the community. I wish you good work.
