Friday, January 20, 2012

Standard String Functions

Discuss the definition of the following standard string functions

A.1.strcpy()   2.strdup()  3.strrev()  4.strcat()  5.substr()  6.strstr() 7.strcmp()
B.1.strncpy()  2.
C.1.itoa()  2.atoi()

strncpy():
Used to copy one portion of a string into another string.The strncpy() function takes three arguments: the first argument is the destination string, the second argument is the source string, and the third argument is an integer representing the number of characters you want to copy from the source string to the destination string.

Example:
strncpy(dest_str1, source_str, 11);

Note:
dest_str had to be initialized to null characters (\0). This is because the strncpy() function does not automatically append a null character to the string you are copying to. Therefore, you must ensure that you have put the null character after the string you have copied, or else you might wind up with garbage being printed.

No comments:

Post a Comment