#include <string.h>
#include <stdio.h>
#include <tchar>
int main( void )
{
   TCHAR buffer[] = _T("This is the buffer text");
   TCHAR *newstring;
   _tprintf( _T("Original: %s\n"), buffer );
   newstring = _tcsdup( buffer );
   _tprintf( _T("Copy:     %s\n"), newstring );
   free( newstring );
}

这是这个函数的标准调用demo,需要注意的是,即使buffer为空,返回的字符串也不是NULL,而是一个有地址的空字符串,这样直接判断地址是否为空,不为空再free会出错,这是改bug的体会

相关文章:

  • 2021-08-08
  • 2022-12-23
  • 2022-02-17
  • 2022-12-23
  • 2022-01-06
  • 2022-12-23
  • 2022-02-14
  • 2022-12-23
猜你喜欢
  • 2021-09-23
  • 2021-06-03
  • 2021-07-07
  • 2022-12-23
  • 2021-12-30
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案