DMP - Chapter 11

Character String and String functions

String constants

#include < stdio.h>

void main(void)
	printf("%s, %p, %c\n", "We", "love", *"snow");

String arrays and initialization

char m1[] = "We love snow";
char m1[] = {'W', 'e', ' ', 'l', 'o', 'v', 'e',  ' ', 's', 'n', 'o', 'w', '\0'};
m1 == &m1[0], *m1 == 'W', *(m1 + 1) == m1[1] == 'u'
char *m2 = "We love snow";

Array vs pointer

Arrays of strings

char *m3[3] = {"We", "love", "snow"}; (ragged array)
char m4[3][4] =  {"We", "love", "snow"}; (rectangular array)

Pointers and strings

#include < stdio.h>

void main(void)
	static char * mesg = "Don't be a fool!";
	static char * copy;

	copy = mesg;
	printf("%s\n", copy);
	printf("mesg= %s &mesg= %p; value= %p\n", 
		mesg, &mesg, mesg");
	printf("copy= %s &copy= %p; value= %p\n", 
		copy, &copy, copy");

String input

String output


String functions

Sorting strings