Sams Teach Yourself C in 21 Days

(singke) #1
LISTING17.5 strcat.c. Using strcat()to concatenate strings
1: /* The strcat() function. */
2:
3: #include <stdio.h>
4: #include <string.h>
5:
6: char str1[27] = “a”;
7: char str2[2];
8:
9: int main( void )
10: {
11: int n;
12:
13: /* Put a null character at the end of str2[]. */
14:
15: str2[1] = ‘\0’;
16:
17: for (n = 98; n< 123; n++)
18: {
19: str2[0] = n;
20: strcat(str1, str2);
21: puts(str1);
22: }
23: return 0;
24: }

ab
abc
abcd
abcde
abcdef
abcdefg
abcdefgh
abcdefghi
abcdefghij
abcdefghijk
abcdefghijkl
abcdefghijklm
abcdefghijklmn
abcdefghijklmno
abcdefghijklmnop
abcdefghijklmnopq
abcdefghijklmnopqr
abcdefghijklmnopqrs
abcdefghijklmnopqrst
abcdefghijklmnopqrstu
abcdefghijklmnopqrstuv

488 Day 17

OUTPUT

28 448201x-CH17 8/13/02 11:13 AM Page 488

Free download pdf