Strings in C


In C, strings are a 1-d array of characters that has a null terminator. All of the string functions provided in the string.h library work on the assumption that there is a null terminator as the last character in the string. The string "Brenda" has 6 characters and the null terminator so the array must be declared to be at least size 7, "computer science" has 16 characters (the space is a character) and the null terminator so the array must declared to be of at least size 17.
As with arrays, in order to use a string, you need some tools. You must be able to declare strings, input them, output them, compare them, copy one string to another one (assignment concept), etc.
Languages provide the most common tools needed as part of the language.
Example - swapping strings - NOTE: I assume that MAX is used by all the strings. This may NOT be a reasonable assumption which makes the declaration and use of temp a weak design but this is still the most widely used method of swapping 2 strings.
   void swap_strings(char string1[], char string2[])
   {
     char temp[MAX];

     strcpy(temp, string1)
     strcpy(string1, string2)
     strcpy(string2, temp)
   }