1 / 5

Strings in C are my friend, and they can be yours, too.

Strings in C are my friend, and they can be yours, too. An inspiring and epic tale by Erik Speyer, John Sullivan, and Dane Bennington. Strings in C.

daw
Download Presentation

Strings in C are my friend, and they can be yours, too.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Strings in C are my friend, and they can be yours, too. An inspiring and epic tale by Erik Speyer, John Sullivan, and Dane Bennington

  2. Strings in C • There is no ‘string’ type in C, rather, an array of characters with some useful functions available to the user to manipulate the array as if it were a string. • These functions mostly reside in the string.h header file

  3. String.h – Manipulating Strings • stpcpy - Copy one string into another. • strcmp - Compare two strings alphabetically • strerror – Get a specific error message string • strlen – Returns the length of the string • strncat – Concatenate two strings together • strncmp – Compares n-chars in two strings • strncpy - Copy n-chars of one string into another • strcasecmp - case insensitive version of strcmp() • sprintf – Outputs a string to a buffer

  4. String.h – Searching Strings • strchr –First occurrence of a char in the string. • strrch –Last occurrence of a char in the string. • strstr – The first occurrence of one string in another • strspn – Chars in two strings that match • strcspn- Chars in two strings that don’t match • strtok – Split a string at a specified character • strpbrk – Looks for any char between two strings.

  5. Idiosyncrasies of Strings in C • Strings have no idea how long they are. They get around this shortcoming by using a null-character (‘\0’) that tells the subroutine it can stop looking. • Strings have a set size. Remember this if you are appending strings – make sure the final string is big enough to hold both of them. • String commands that take a part of a string make a string that is not null-terminated, so watch out. • The string tokenizer (strtok) will return the first tokenized word if you pass it a string, but all subsequent calls to find the next token in the string require you to pass it null(!).

More Related