help with C-strings

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <cstring>
#include <cctype>

using std::cin;
using std::cout;
using std::endl;

// Add your function prototypes here
char* copy( char*, const char*);

char* replaceCopy(char*, const char*,char, char);


int main()
   {
   const int NAMESIZE = 80;
   char names[][NAMESIZE] = {"Bubba", "Abba", "Freddo", "Frida", "Buddy", ""};
   char name[NAMESIZE];

   // Now let's test the functions.
   cout << "Copy \"Abba\", should see \"Abba\".\n";
   copy(name, names[1]);
   cout << name << endl << endl;

   cout << "Replace 'd' in \"Buddy\" with 'y', should see \"Buyyy\".\n";
   replaceCopy(name, names[4], 'd', 'y');
   cout << name << endl << endl;


   
   return 0;
   }

// Add your function definitions here

char* copy(char* destination, const char* source)
{
	strcpy( destination,source);
}


char* replaceCopy(char* destination, const char* source, char target, char replace)
{

}

// For "Abby".Copy a string from the address specified by source to that specified by destination. You may assume that there is enough space allocated for the destination array to hold a copy of the source string. Note that source and destination are both pointers. Return a pointer to the start of the copied string.

char* replaceCopy(char* destination, const char* source, char target, char replace)

//For "Buddy".Copy a string in which each instance of a "target" character is replaced by the "replace" character, from the address specified by source to that specified by destination. Return a pointer to the start of the copied string.


Having a little trouble, I can copy "Abby" easily using the strcpy function, however I have no clue how to replace and copy "Buddy". Any suggestions?
Topic archived. No new replies allowed.