9+String

Embed Size (px)

Citation preview

  • 8/17/2019 9+String

    1/14

    Dr. Siti Barirah Ahmad Anas

    [email protected]

    Room A.04.89

    ECC3101 COMPUTERPROGRAMMING

    String

    mailto:[email protected]:[email protected]

  • 8/17/2019 9+String

    2/14

  • 8/17/2019 9+String

    3/14

    •  Tehno!o"y#riented

      •  Business Dri$en•  Sustainab!e De$e!opment•  %n$ironmenta!

    &riend!y

       L   E

       A   R   N

       I   N   G

       O   U   T   C   O

       M   E•  To understand the onept o) strin" and

    array

    •  To de!are* initia!i+e* assi"n and aessstrin"

     To imp!ement (-strin" and harater)untions

  • 8/17/2019 9+String

    4/14

    •  Tehno!o"y#riented

      •  Business Dri$en•  Sustainab!e De$e!opment•  %n$ironmenta!

    &riend!y

    • A pointer-based strin" – Array o) haraters endin" ,ith a nu!!

    terminator 0/

     – 0/ indiates strin" termination inmemory

    • 'mp!emented either usin" – ointer synta1 – Array synta1

       I   N   T   R

       O   D   U

       C   T   I   O

       N

  • 8/17/2019 9+String

    5/14

    •  Tehno!o"y#riented

      •  Business Dri$en•  Sustainab!e De$e!opment•  %n$ironmenta!

    &riend!y

    char city[7] = “Dallas”; // array//syntax

    char *pCity = “Dallas”; // pointer//syntax

    • %ah reates se2uene o)haraters D/* a/* !/* !/* a/* s/*

    0/

       D   E   C

       L   A   R   A   T   I   O   N

  • 8/17/2019 9+String

    6/14

    •  Tehno!o"y#riented

      •  Business Dri$en•  Sustainab!e De$e!opment•  %n$ironmenta!

    &riend!y

    cout

  • 8/17/2019 9+String

    7/14

    •  Tehno!o"y#riented

      •  Business Dri$en•  Sustainab!e De$e!opment•  %n$ironmenta!

    &riend!y

    • Strin" an be read )rom the5eyboard usin"

    1" cin #R

    #" cin"$etline(char array[]% intsi&e% char deli'itChar!

    %.".

    char city[)];cout

  • 8/17/2019 9+String

    8/14

    •  Tehno!o"y#riented

      •  Business Dri$en•  Sustainab!e De$e!opment•  %n$ironmenta!

    &riend!y

    %.". 7 cin"$etline(char array[]% intsi&e% char deli'itChar!

    char city[)];

    cout

  • 8/17/2019 9+String

    9/14

    •  Tehno!o"y#riented

      •  Business Dri$en•  Sustainab!e De$e!opment•  %n$ironmenta!

    &riend!y

    Function Description

    int strlen(char *s1! Returns strin" !en"thchar strcpy(char *s1% constchar *s#!

    (opies s7 to s. s $a!ue is returned

    char strncpy(char *s1% constchar *s#% si&e3t n!

    (opies at most n haraters in s7 tos. s $a!ue is returned

    char strcat(char *s1% const

    char *s#!

    Append s7 to s. &irst harater o)

    s7 o$er,rites nu!! o) s. s $a!ue isreturned

    char strncat(char *s1% constchar *s#% si&e3t n!

    Append at most n haraters o) s7to s. &irst harater o) s7o$er,rites nu!! o) s. s $a!ue isreturned

    char strc'p(char *s1% const

    char *s#!

    Returns $a!ue !ess than 0* 0 or

    "reater than 0* i) s s7* s s7or s : s7* respeti$e!y

    char strnc'p(char *s1% constchar *s#% si&e3t n!

    Returns $a!ue !ess than 0* 0 or"reater than 0* i) s s7* s s7or s : s7 ;)or the

  • 8/17/2019 9+String

    10/14

    •  Tehno!o"y#riented

      •  Business Dri$en•  Sustainab!e De$e!opment•  %n$ironmenta!

    &riend!y

       E   !   A   M

       P   L   E  

       S   T   R   C

       P   "

    4include

  • 8/17/2019 9+String

    11/14

    •  Tehno!o"y#riented

      •  Business Dri$en•  Sustainab!e De$e!opment•  %n$ironmenta!

    &riend!y

    4include

  • 8/17/2019 9+String

    12/14

    •  Tehno!o"y#riented

      •  Business Dri$en•  Sustainab!e De$e!opment•  %n$ironmenta!

    &riend!y

       E   !   A   M

       P   L   E  

       S   T   R   C

       M   P

    4include

  • 8/17/2019 9+String

    13/14

    •  Tehno!o"y#riented

      •  Business Dri$en•  Sustainab!e De$e!opment•  %n$ironmenta!

    &riend!y

    Function Description

    isdi$it(a! Returns true i) a is a di"it

    isalpha(a! Returns true i) a is a !etter

    isalnu'(a! Returns true i) a is a !etter or a di"it

    islo?er(a! Returns true i) a is a !o,erase !etter

    isupper(a! Returns true i) a is an upperase !etter

    tolo?er(a! Returns the !o,erase e2ui$a!ent o) a* i) a is anupperase !etter* other,ise returns itse!) 

    toupper(a! Returns the upperase e2ui$a!ent o) a* i) a is a!o,erase !etter* other,ise returns itse!) 

       C   #

       A   R   A   C

       T   E   R

       F   U   N   C   T   I   O   N   S

    R

  • 8/17/2019 9+String

    14/14

    •  Tehno!o"y#riented

      •  Business Dri$en•  Sustainab!e De$e!opment•  %n$ironmenta!

    &riend!y4include