C Programming

Consider the following,

	char  *text_pointer = "Hello said the man.";

This defines a character pointer called text_pointer which points to the start of the text string 'Hello said the man'. This message could be printed out by

	printf("%s", text_pointer);

text_pointer holds the memory address of where the message is located in memory.

Lets append two strings together by using arrays.

	#include <stdio.h>

		static char string1[]={'H','e','l','l','o',' ' };
		static char string2[]={'s','a','i','d',' ','t','h','e',' ','m','a','n','.'  };
		char  string3[25];
		int string_length1 = 6, string_length2 = 13, n;

		for( n = 0; n < string_length1; ++n )
			string3[n] = string1[n];

		for( n = 0; n < string_length2; ++n )
			string3[n + string_length1] = string2[n];

		for(n = 0; n < (stringlength1+string_length2); ++n)
			printf("%c", string3[n]);

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