cs161examples/cs161BW1/ourStrcat.cpp

32 lines
456 B
C++

#include <iostream>
using namespace std;
//a slightly different demo of strcat
//can we pull something out of this into a separate function?
void strCat(char s1[], char s2[]){
int i = 0;
int j = 0;
while (s1[i] != '\0'){
i++;
}
while (s2[j] != '\0'){
s1[i+j] = s2[j];
j++;
}
s1[i+j] = '\0';
}
int main(){
char strang[100] = "Hello";
char strung[100] = " goodbye";
strCat(strang,strung);
cout << strang << endl;
}