Next: Exercises Up: Arrays Previous: Single and Multi-dimensional Arrays

Strings

In C Strings are defined as arrays of characters. For example, the following defines a string of 50 characters:

C has no string handling facilities built in and so the following are all illegal:

However, there is a special library of string handling routines which we will come across later (also see AppendiX ).

To print a string we use printf with a special %s control character:

printf(``%s'',name);

NOTE: We just need to give the name of the string.

In order to allow variable length strings the 0 character is used to indicate the end of a string.

So we if we have a string, char NAME[50]; and we store the ``DAVE'' in it its contents will look like:


Dave.Marshall@cm.cf.ac.uk
Wed Sep 14 10:06:31 BST 1994