UMBC CMSC 201 Spring '02 CSEE | 201 | 201 S'02 | lectures | news | help

Strings

  • Strings are sequences of characters that are terminated with a the special character, the NULL character, '\0'.

  • Strings are represented as arrays of characters, where the last character of the string is the NULL character, '\0'.

  • This combination declaration and initialization: char str[5] = "cat"; has the following representation.

    str

    FE09

    'c'

    'a'

    't'

    '\0'

    .

    Have you heard this one??


    These two strings walk into a bar and sit down.
    The bartender says, "So what'll it be?"

    The first string says, "I think I'll have a beer quag fulk boorg jdk^CjfdLk jk3 s d#f67howe%^U r89nvy~~owmc63^Dz x.xvcu"

    "Please excuse my friend," the second string says, "He isn't null-terminated."


  • Many functions have already been written for manipulating strings and they are found in the ANSI C string library.

  • To use functions in this library you'll need to #include <string.h>


    CSEE | 201 | 201 S'02 | lectures | news | help