PLEASE NOTE: the upgrades to this server,, have not yet been completed.
Hopefully the changes will be completed on THURSDAY 8th December.
Web-based programs, such as csmarks, cssubmit, and the help fora, will be unavailable at some time on Thursday 8th.
  It's UWAweek 49


This forum is provided to promote discussion amongst students enrolled in CITS2002 Systems Programming.
Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.

Displaying selected article
Showing 1 of 919 articles.
Currently 5 other people reading this forum.

 UWA week 40 (2nd semester, week 10) ↓
SVG not supported

Login to reply

3:02am Mon 3rd Oct, Christopher M.

"Gihad Coorey" [email protected] wrote:

From what I understand, strcat_p only works as intended when there just happens to be enough memory adjacent to the dest string where we can copy the entire src (plus '\0'). If there happened to be other (meaningful but currently irrelevant) data in the adjacent memory, wouldn't we be rewriting this memory by doing "*dest = *src" (where dest is a pointer to the last character in destination string)?

Yes. You need to provide sufficient space for dest before calling strcat_p()

How do you increase the amount of space available for the destination string to be lengthened by? Are you not passing a pointer to a string that already has a defined size at runtime(?)

You can increase the space associated with a pointer, and copy its original data too, with realloc() but, of course, that requires the pointer to have first been obtained through an earlier call to malloc() or realloc().

Otherwise, you need to first allocate new memory long enough to hold the original and the new data.

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  1:17AM Sep 14 2022
Privacy policy