ABSTRACT

This chapter describes how to read and write strings and covers some of the most important string handling functions in the C library. A string literal is a sequence of characters enclosed in double quotes. C treats it as a nameless character array. The C library provides a rich set of functions to perform operations on strings. The chapter presents some of the most commonly used. The strlen() Function, strlen() returns the number of characters in the string pointed to by str, not counting the null character. The strcpy() and strncpy() Functions, strcpy() copies the string pointed to by src into the memory pointed to by dest. Strncpy() is similar to strcpy(), with the difference that only the first count characters of the string pointed to by src will be copied into dest. The strcat() Function appends the null character and returns dest, which points to the resulting string. The strcmp() and strncmp() Functions, compares the str1 with the str2.