September 1998
Intermediate to advanced
848 pages
20h 13m
English
Again, we will use library functions. C has three standard library functions for printing strings. They are puts(), fputs(), and printf().
The puts() function is very easy to use. Just give it the address of a string for an argument. Listing 11.8 illustrates some of the many ways to do this.
/* put_out.c -- using puts() */
#include <stdio.h>
#define DEF "I am a #defined string."
int main(void)
{
char str1[80] = "An array was initialized to me.";
char * str2 = "A pointer was initialized to me.";
puts("I'm an argument to puts().");
puts(DEF);
puts(str1);
puts(str2);
puts(&str1[4]);
puts(str2+4);
return 0;
}
|
The output is this:
I'm an argument to puts(). I am a #defined ...
Read now
Unlock full access