9. Stringsx #

Created Thursday 08 April 2021

What is a str

http://www.cplusplus.com/doc/tutorial/ntcs/ Relation between strings and NULL terminated character arrays, they are the same! Except that strings are managed dynamically.


char nula[] =“jhwev” string nula_string = nula;// converted to string


inbuilt function: in

  1. strlen(char * str); for “hello”, it returns 5.
  2. strcmp(char* s1, har* s2).
    • If it returns 0, both strings are equal, for all non zero outputs, strings are not equal.
    • If +ve, then the s1 > s2. (Assuming all characters in both are of the of the same case)
    • And -ve means s1, s2. (Assuming all characters in both are of the of the same case)
  3. strcpy(char *destination, char *source). Will copy the string source to the destination(including the null character), assuming that memory is enough for copying).
    • source can be a string literal as well.
    • It copies the null character too.
  4. strncpy(char *destination, char *source, int n). Copies n characters from source to string(i.e overwrites).
    • **Does **not append the null character.
    • if source is of length less than ‘n’, then it appends null to all the remaining characters.