-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrcat.cpp
More file actions
36 lines (29 loc) · 725 Bytes
/
strcat.cpp
File metadata and controls
36 lines (29 loc) · 725 Bytes
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
/********************************************************
CS111 Lab on c-strings
Template prepared by Kazumi Slott
********************************************************/
#include <iostream>
using namespace std;
void myStrcat(char dest[], const char source[]);
int main()
{
char str2[80] = "Dave "; //puts "Dave" in string
myStrcat(str2, "Smith");
cout << str2 << endl; //Dave Smith
return 0;
}
void myStrcat(char dest[], const char source[])
{
int d;
//Move d to the end of dest ('\0')
for(d=0; dest[d] != '\0'; d++)
;
//put source into dest
int i;
/*for(i=0; source[i] != '\0'; d++, i++)
dest[d] = source[i];
OR,
*/
for(i=0; source[i] != '\0'; i++)
dest[d+i] = source[i];
}