Question 8.1

Why doesn't

strcat(string, '!');
work?


There is a very real difference between characters and strings, and strcat concatenates strings.

Characters in C are represented by small integers corresponding to their character set values (see also question 8.6). Strings are represented by arrays of characters; you usually manipulate a pointer to the first character of the array. It is never correct to use one when the other is expected. To append a ! to a string, use

	strcat(string, "!");

See also questions 1.32, 7.2, and 16.6.

References: CT&P Sec. 1.5 pp. 9-10


Read sequentially: prev next up top


This page by Steve Summit // Copyright 1995 // mail feedback