seminar string functions

Upload: merin-thomas

Post on 10-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 SEMINAR String Functions

    1/17

    By Team-1

    Prasanna A

    Alka Mary Abraham

    Minimol T KJacob Tisson

  • 8/8/2019 SEMINAR String Functions

    2/17

    SYNTAX

    char *strcat(char *dest, const char *src);

    DESCRIPTION

    strcat() is used to concatenate a null-terminated string to end of

    another string variable.

    This is equivalent to pasting one string onto the end of another,

    overwriting the null terminator.

    There is only one common use for strcat().

    The strcat function concatenates or appends source to destination. All

    characters from source are copied including the terminating character.

  • 8/8/2019 SEMINAR String Functions

    3/17

    ` char S[25] = "world!";

    ` char D[25] = "Hello, ";

    ` Concatenating the whole string S onto D:` strcat(D, S);

  • 8/8/2019 SEMINAR String Functions

    4/17

  • 8/8/2019 SEMINAR String Functions

    5/17

    ` Returned String : HelloHellooo

    ` Concatenated String : HelloHellooo

  • 8/8/2019 SEMINAR String Functions

    6/17

    SYNTAX

    char *strncat(char *s1, const char *s2, size_t n);

    DESCRIPTION` The strncat() function appends up to n characters from

    string s2 to string s1 and then appends a terminating null

    character.

    `

    The initial character ofs2

    overwrites the null character atthe end ofs1.

    ` Subsequent characters in s2 are appended to s1 until either

    the end of s2 is reached or n characters have been copied.

  • 8/8/2019 SEMINAR String Functions

    7/17

    ` If copying takes place between objects that overlap, the behavior is

    undefined.

    ` The function strncat() does not allocate any storage. The caller must

    insure that the buffer pointed to by s1 is long enough to hold the added

    characters.

    DESCRIPTIONOF Strncat()

  • 8/8/2019 SEMINAR String Functions

    8/17

    #include

    int main()

    {

    char string1[20];char string2[20];

    strcpy(string1, "Hello");

    strcpy(string2, "Hellooo");

    printf("Returned String : %s\n", strncat(string1,string2,4));

    printf("Concatenated String : %s\n", string1 );

    return 0;

    }

  • 8/8/2019 SEMINAR String Functions

    9/17

    ` Returned String : HelloHell

    ` Concatenated String : HelloHell

  • 8/8/2019 SEMINAR String Functions

    10/17

    SYNTAX

    char *strchr(const char *s, intc);

    DESCRIPTION

    ` The strchr() function shall locate the first occurrence ofc

    (converted to a char) in the string pointed to by s.

    ` The terminating null byte is considered to be part of thestring.

    ` The strchr() function returns a pointer to the first

    occurrence of character c located within s.

  • 8/8/2019 SEMINAR String Functions

    11/17

    #include #include intmain()

    {char s[10] = Locate";char *pos = strchr(s, a');

    if(pos)printf("Character a' is found at position %d.\n", pos+1);

    elseprintf("Character a is not found.\n");return 0;

    }

  • 8/8/2019 SEMINAR String Functions

    12/17

    ` Character a' is found at position 4.

  • 8/8/2019 SEMINAR String Functions

    13/17

    SYNTAX

    size_t strspn(const char *s1, const char *s2);

    DESCRIPTION

    ` The strspn() function computes the length of the maximum initial

    segment of the string s1 that consists entirely of characters from the

    string s2.

    ` Its purpose is to determine the size, location, and existence of strings

    in memory.

  • 8/8/2019 SEMINAR String Functions

    14/17

    ` The strspn() function returns the index of the first character in str1

    that doesn't match any character in str2.

    EXAMPLE:

    ` Given s1= abcdef and s2 =abc, the function returns 3.

  • 8/8/2019 SEMINAR String Functions

    15/17

  • 8/8/2019 SEMINAR String Functions

    16/17

    ` The portion of 'cabbage' containing only a, b, or c is

    5 bytes long

  • 8/8/2019 SEMINAR String Functions

    17/17

    ANY QUERIES