\ DMP - Chapter 11

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] == 'e'
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

Do-it-yourself

String functions

Sorting strings

The ctype.h character functions

Command-line arguments

String-to-number conversions


Go to Ich's Home Page
Go to the Peabody Home Page
For comments or questions email to: ich@peabody.jhu.edu