-
Notifications
You must be signed in to change notification settings - Fork 0
/
xstrcpy.c
48 lines (34 loc) · 1.13 KB
/
xstrcpy.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
44
45
46
47
48
#include <stdio.h>
#include <string.h>
#define MAX 100
void xstrcpy(char *, const char *);
/*
While passing values, keep your head cool.... because if you think
we will pass something of the kind &'n' where n is anything, then you are wrong.
REMEMBER: Whenever we are passing an array entirely, we are PASSING THE "ADDRESS
OF THE ZEROTH ELEMENT", I.E here the address of the zeroth element of the char
arrays.
*/
int main() {
char yourString[MAX], myString[MAX], myString2[MAX];
printf("Enter Your String: ");
gets(yourString);
strcpy(myString, yourString);
printf("ACCORDING TO C's FUNCTION ....");
printf("Your String is %s\n", yourString);
printf("My String is %s\n", myString);
printf("\n\n");
xstrcpy(myString2, yourString);
printf("ACCORDING TO MY FUNCTION ....");
printf("Your String is %s\n", yourString);
printf("My String is %s\n", myString2);
return 0;
}
void xstrcpy(char *target, const char *source) {
while (*source != '\0') {
*target = *source;
target++;
source++;
}
*target = '\0';
}