Copy a String
For this activity,
you’ll be writing the function stringCopy
:
void stringCopy (char *destination, char *source, int destSize);
It takes a string in the source
buffer,
and copies it to the destination
buffer,
which is destSize
elements in size.
If there are more characters in source
than there is array space in destination,
you should stop after you have filled the array.
You should always make sure that
your function null-terminates
the
destination` array.
Download
stringCopy.c
,
or copy it into your current directory on a CSE system by running
$ cp /web/cs1511/17s2/week05/files/stringCopy.c .
We’ve provided a simple test to help you build your solution. You should write more tests to demonstrate your solution works.
To run some simple automated tests:
$ 1511 autotest stringCopy
To run Styl-o-matic:
$ 1511 stylomatic stringCopy.c Looks good!
You’ll get advice if you need to make changes to your code.
Submit your work with the give command, like so:
$ give cs1511 wk05_stringCopy
Or, if you are working from home, upload the relevant file(s) to the wk05_stringCopy activity on Give Online.