STRDUP



  • HI!
    wozu ist diese string funktion nützlich?

    mfg geissbock



  • _strdup, _wcsdup, _mbsdupSee Also

    All versions of the C run-time libraries.
    Duplicate strings.

    char *_strdup(
    const char *strSource
    );
    wchar_t *_wcsdup(
    const wchar_t *strSource
    );
    unsigned char *_mbsdup(
    const unsigned char *strSource
    );
    Parameters
    strSource
    Null-terminated source string.
    Return Value
    Each of these functions returns a pointer to the storage location for the copied string or NULL if storage cannot be allocated.



  • Erzeugt die eine Kopie des Orginalstrings inclusive der Speicherreservierung, andernfalls müßtest du so etwas machen

    char Orginal[]={"irgendein beliebiger Text... "};
    char *Kopie;
    
     if 0==(Kopie=malloc(strlen(Orginal)+1))
     {
      // Errorhandling
     }
     strcpy(Kopie,Orginal);
    // .... und irgenwann das zugehörige free
    
    //  Im Gegensatz dazu
     if (0 ==(Kopie=strdup(Orginal))
      {
      // Errorhandling
      }
    


  • thx

    @pad
    solche antworten leibe ich. kurz und vielsagend. so gefällt mir das.


Anmelden zum Antworten