C Programming

POINTERS AND CHARACTER STRINGS
A pointer may be defined as pointing to a character string.


	#include <stdio.h>

	main()
	{
		char *text_pointer = "Good morning!";

		for( ; *text_pointer != '\0'; ++text_pointer)
			printf("%c", *text_pointer);
	}

or another program illustrating pointers to text strings,


	#include <stdio.h>

	main()
	{
		static char *days[] = {"Sunday", "Monday", "Tuesday", "Wednesday", \
							"Thursday", "Friday", "Saturday"};
		int i;

		for( i = 0; i < 6; ++i )
			printf( "%s\n", days[i]);
	}

Remember that if the declaration is,


   char *pointer = "Sunday";

then the null character { '\0' } is automatically appended to the end of the text string. This means that %s may be used in a printf statement, rather than using a for loop and %c to print out the contents of the pointer. The %s will print out all characters till it finds the null terminator.


©Copyright B Brown. 1984-1999. All rights reserved.