4 /* print contents of array */
5 void print_array(char s
[])
8 for(i
= 0; i
< strlen(s
); i
++)
15 Copy at most n chars of string source into string dest.
16 Pad with '\0' if source has fewer chars than dest.
19 char *ss_strncpy(char *dest
, const char *source
, int n
)
22 if(n
>= 0 || n
== '\0')
24 while(--n
>= 0 && (*dest
++ = *source
++) != '\0')
35 Appends n chars of src into the end of dest.
37 If null encountered before n, then copy null and no more.
39 If n is zero or negative, then function has not effect.
42 char *ss_strncat(char *dest
, const char *source
, size_t n
)
44 while(*dest
) { ++dest
; } // find pointer val for end of string s
45 while((--n
>= 0) && (*dest
++ = *source
++) != '\0');
51 Compares contents of string s1 with contents of s2.
53 If s1 < s2 returns < 0
55 If s1 > s2 returns > 0
58 int ss_strncmp(const char *s1
, const char *s2
, size_t n
)
61 while(--n
>= 0 && *s1
!= '\0' && *s2
!= '\0')
64 if(*s1
++ == *s2
++) { continue; }
75 char source
[] = { "Destination after..." };
76 char dest
[] = { "This is the destination before..." };
82 ans
= strncpy(dest
, source
, 20);
89 char source2
[] = { "Destination after..." };
90 char dest2
[] = { "This is the destination before..." };
94 ss_strncpy(dest2
, source2
, 20);
99 char info
[] = { "Data To Append. " };
100 char buffer
[50] = { "Beginning of Buffer. " };
102 for(i
= 0; i
<= 2; ++i
)
104 strncat(buffer
, info
, strlen(info
));
110 char smaller
[] = { "12345" };
111 char bigger
[] = { "67890" };
114 size_ans
= ss_strncmp(smaller
, bigger
, 3);
115 printf("%d\n", size_ans
);
117 size_ans
= ss_strncmp(bigger
, bigger
, 3);
118 printf("%d\n", size_ans
);
120 size_ans
= ss_strncmp(bigger
, smaller
, 3);
121 printf("%d\n", size_ans
);