home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Jason Aller Floppy Collection
/
98.img
/
LCNOW2.ZIP
/
EXAMPLES
/
PRINTSTR.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-08-02
|
958b
|
48 lines
/*
* P R I N T S T R
*
* Compare the printing of strings using several
* methods, including indirect access via a pointer.
*/
#include <stdio.h>
#include <string.h>
int
main(void)
{
int i; /* loop index */
int len; /* string length */
char *cp; /* character pointer */
static char string[] = {
"What goes up must come down. Ask a market analyst!\n"
};
/*
* Print the string by using the printf() library function.
*/
printf("Using printf(): ");
printf("%s", string);
/*
* Print the string by using array indexing.
*/
printf("Using an array index: ");
len = strlen(string); /* length of string */
for (i = 0; i < len; ++i)
putchar(string[i]);
/*
* Print the string by using a character pointer.
*/
printf("Using a character pointer: ");
cp = string; /* beginning of string */
while (*cp) {
putchar(*cp);
++cp;
}
return (0);
}