| | | | | |

C String Functions (cont.)

  • possible implementation of strcpy()
  • void strcpy (char* str2, const char* str1)
    {
      while (*str1 != '\0')
      {
        *str2 = *str1;
        ++str2;
        ++str1;
      }
      *str2 = '\0';
    }
    
  • Assumption that str1 is null-terminated used implicitly
  • Assumption that str2 has been allocated sufficient memory used implicitly
  • C string functions do not handle or "worry about" memory management

| | Top of Page | 3. C Strings, Proper Type, and String Objects - 4 of 17