9
9
#include <string.h>
10
10
11
11
char * HACKERRANK_WARMUP_firstN (const char * s , unsigned long n ) {
12
- unsigned long len = strlen (s );
12
+ unsigned long len = strlen_s (s );
13
13
if (n > len ) {
14
14
return NULL ;
15
15
}
@@ -22,15 +22,15 @@ char *HACKERRANK_WARMUP_firstN(const char *s, unsigned long n) {
22
22
return NULL ;
23
23
}
24
24
25
- strncpy (result , s , n );
25
+ strncpy_s (result , s , n );
26
26
27
27
result [n ] = '\0' ;
28
28
29
29
return result ;
30
30
}
31
31
32
32
char * HACKERRANK_WARMUP_lastN (const char * s , unsigned long n ) {
33
- unsigned long len = strlen (s );
33
+ unsigned long len = strlen_s (s );
34
34
if (n > len ) {
35
35
return NULL ;
36
36
}
@@ -43,7 +43,7 @@ char *HACKERRANK_WARMUP_lastN(const char *s, unsigned long n) {
43
43
return NULL ;
44
44
}
45
45
46
- strncpy (result , s + len - n , n );
46
+ strncpy_s (result , s + len - n , n );
47
47
48
48
result [n ] = '\0' ;
49
49
@@ -54,17 +54,18 @@ char *HACKERRANK_WARMUP_timeConversion(const char *s) {
54
54
char * meridian = HACKERRANK_WARMUP_lastN (s , 2 );
55
55
56
56
char * hour_str = HACKERRANK_WARMUP_firstN (s , 2 );
57
- char * time_str = (char * )malloc ((strlen (s ) + 1 ) * sizeof (char ));
57
+ char * time_str = (char * )malloc ((strlen_s (s ) + 1 ) * sizeof (char ));
58
58
if (time_str == NULL ) {
59
59
free (hour_str );
60
60
free (meridian );
61
61
return NULL ;
62
62
}
63
- strcpy (time_str , s );
64
- char * temp_time_str = HACKERRANK_WARMUP_lastN (time_str , strlen (time_str ) - 2 );
63
+ strcpy_s (time_str , s );
64
+ char * temp_time_str =
65
+ HACKERRANK_WARMUP_lastN (time_str , strlen_s (time_str ) - 2 );
65
66
free (time_str );
66
67
time_str = temp_time_str ;
67
- temp_time_str = HACKERRANK_WARMUP_firstN (time_str , strlen (time_str ) - 2 );
68
+ temp_time_str = HACKERRANK_WARMUP_firstN (time_str , strlen_s (time_str ) - 2 );
68
69
free (time_str );
69
70
time_str = temp_time_str ;
70
71
0 commit comments