|
CS256 - Principles of Structured Design
Fall 2021
|
Displaying ./code/sternflCode/str6.c
//string concatenation
#include<stdio.h>
#include<string.h>
char *myStrcat(char *dest, const char *src) {
//find the end of the string in dest
int i=0;
while (dest[i]!=0)
i++;
printf("%d\n", i);
//copy the str to dest
int j=0;
while (src[j]!=0)
{
dest[i]=src[j];
i++;
j++;
}
dest[i]=src[j];
}
int main() {
char dest[200];
char src[200];
//get a string into each array
printf("Please enter the first string ");
scanf("%s", dest);
printf("Please enter the second string ");
scanf("%s", src);
myStrcat(dest,src);
//strcat(dest,src);
printf("%s\n",dest);
return 0;
}
|