Strings

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

char name[50];

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

char firstname[50], lastname[50],fullname[100];

firstname="Tina"; /* Illegal */

lastname="Turner"; /* Illegal */

fullname="Mrs"+firstname+lastname; /* Illegal*/

However, there is a special library of string handling routines which we will come across later .

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:


drago@scri.fsu.edu
Jan. 1997