-
Notifications
You must be signed in to change notification settings - Fork 0
/
xstrcat.c
43 lines (33 loc) · 1.05 KB
/
xstrcat.c
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
#include <stdio.h>
#include <string.h>
#define MAX 100
void xstrcat(char *, char *);
int main() {
char yourString[MAX], newString[2 * MAX], yourString2[MAX], newString2[2 * MAX];
printf("Enter your String: ");
gets(yourString);
printf("Enter the String to be concatenated at the beginning: ");
gets(newString);
strcat(newString, yourString);
printf("ACCORDING TO C's FUNCTION....\n");
printf("New String is: %s\n", newString);
printf("\n\n");
printf("Enter your String: ");
gets(yourString2);
printf("Enter the String to be concatenated at the beginning: ");
gets(newString2);
xstrcat(newString2, yourString2);
printf("ACCORDING TO MY FUNCTION....\n");
printf("New String is: %s\n", newString2);
return 0;
}
// STRCAT made by us, same algo
void xstrcat(char *target, char *source) {
target = target + (strlen(target));
while (*source != '\0') {
*target = *source;
target++;
source++;
}
*target = '\0';
}