Witam przy takim kodzie:
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char t1[] = { "tekst tablicy t1 " };
char t2[120];
strcpy_s(t1,t2);
cout << t2 << endl;
strncpy_s(t1, "strncpy t1", 3 );
cout << t2 << endl;
strcpy_s(t1, "strcpy t1 ");
cout << t1 << " i " << t2 << endl;
system("pause");
}
Odpala sie DoS lecz się zawiesza i wywala błąd okienkowy coś że za mało miejsca a w Microsoft Visual C++ expres 2010 wywala mi coś takiego:
/***
*tcscpy_s.inl - general implementation of _tcscpy_s
*
Copyright (c) Microsoft Corporation. All rights reserved.
*Purpose:
This file contains the general algorithm for strcpy_s and its variants.
****/
_FUNC_PROLOGUE
errno_t __cdecl _FUNC_NAME(_CHAR *_DEST, size_t _SIZE, const _CHAR *_SRC)
{
_CHAR *p;
size_t available;/* validation section */ _VALIDATE_STRING(_DEST, _SIZE); _VALIDATE_POINTER_RESET_STRING(_SRC, _DEST, _SIZE); p = _DEST; available = _SIZE; while ((*p++ = *_SRC++) != 0 && --available > 0) { } if (available == 0) { _RESET_STRING(_DEST, _SIZE); _RETURN_BUFFER_TOO_SMALL(_DEST, _SIZE); } _FILL_STRING(_DEST, _SIZE, _SIZE - available + 1); _RETURN_NO_ERROR;
}