File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed
03-elementary_data_structures/3.06-strings/exercises Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change 6
6
7
7
char * str_cat (char * s1 , char * s2 )
8
8
{
9
- char * res ;
10
- int i , j ;
9
+ char * res , * head ;
10
+ int i = 0 , j ;
11
11
12
12
res = malloc ((strlen (s1 ) + strlen (s2 ) + 1 ) * sizeof (char ));
13
+ head = res ;
13
14
if (res != NULL )
14
15
{
15
16
while (s1 [i ] != '\0' )
16
- res [ i ] = s1 [i ++ ];
17
+ * res ++ = s1 [i ++ ];
17
18
j = i ;
18
19
i = 0 ;
19
20
while (s2 [i ] != '\0' )
20
- res [ j ++ ] = s2 [i ++ ];
21
+ * res ++ = s2 [i ++ ];
21
22
res [j ] = '\0' ;
22
23
}
23
- return res ;
24
+ return head ;
24
25
}
25
26
26
27
char * str_cpy (char * s )
@@ -30,7 +31,7 @@ char *str_cpy(char *s)
30
31
res = malloc ((strlen (s ) + 1 ) * sizeof (char ));
31
32
head = res ;
32
33
if (res != NULL )
33
- while (* res ++ = * s ++ );
34
+ while (* res ++ = * s ++ )
34
35
return head ;
35
36
}
36
37
You can’t perform that action at this time.
0 commit comments