File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
2
* Exercise 5-3. Write a pointer version of the function strcat that we showed
3
3
* in Chapter 2: strcat(s,t) copies the string t to the end of s.
4
+ *
4
5
* By Faisal Saadatmand
5
6
*/
6
7
@@ -12,18 +13,19 @@ void strCat(char *, char *);
12
13
/* concatenate t to end of s; s must be big enough */
13
14
void strCat (char * s , char * t )
14
15
{
15
- while (* s ) /* find end of s */
16
+ while (s && * s ) /* find end of s */
16
17
++ s ;
17
- while ((* s ++ = * t ++ )) /* copy t */
18
+ while (s && t && (* s ++ = * t ++ )) /* copy t */
18
19
;
19
20
}
20
21
21
22
int main (void )
22
23
{
23
- char string1 [64 ] = { "test this " };
24
- char string2 [] = { "function " };
24
+ char str1 [64 ] = { "conca " };
25
+ char str2 [] = { "tonate " };
25
26
26
- strCat (string1 , string2 );
27
- printf ("%s\n" , string1 );
28
- return 0 ;
27
+ strCat (str1 , str2 );
28
+ printf ("%s\n" , str1 );
29
+
30
+ return 0 ;
29
31
}
You can’t perform that action at this time.
0 commit comments