home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C by Discovery (4th Edition)
/
C_By_Discovery_4th_Edition.tar
/
C_By_Discovery_4th_Edition
/
_DISK_
/
ch5
/
strngerr.c
< prev
next >
Wrap
C/C++ Source or Header
|
2005-06-16
|
1KB
|
39 lines
/* strngerr.c
*
* Synopsis - Initializes two strings and displays the
* strings and their locations. Displays the
* strings again after concatenating the
* second string to the end of the first one.
*
* Objective - To demonstrate a common error in memory
* allocation when using the string library
* functions.
*/
/* Include Files */
#include <stdio.h>
#include <string.h>
int main( void )
{
char *string1 = "I know an old lady who swallowed a ";
char *string2 =
"spider that wiggled and jiggled and tickled inside her";
printf( string1 );
printf( string2 );
/* Note 1 */
printf( "\nstring1 begins at %p, and ends at %p.\n",
string1, string1 + strlen( string1 ) );
printf( "string2 begins at %p, and ends at %p.\n\n",
string2, string2 + strlen( string2 ) );
/* Note 2 */
strcat( string1, " horse. She's dead of course." ); /* ERROR */
printf( string1 );
printf( string2 );
printf( " \n" );
return 0;
}