|
/*
strcpyn.cpp
Copia con controllo sulla dimensione (CRT).
Luca Piergentili, 15/05/98
lpiergentili@yahoo.com
http://www.geocities.com/lpiergentili/
*/
#include "env.h"
#include "pragma.h"
#include <string.h>
#include "strcpyn.h"
/*
strcpyn()
Passare sizeof, copia sizeof - 1, dimensionare quindi il buffer con la quantita' + 1:
char s1[DIM+1];
char* p = "...";
strcpyn(s1,p,DIM+1); -> s1[DIM+1] = 0
*/
char* strcpyn(char* s1,const char *s2,int size)
{
if(!s1)
return(NULL);
if(!s2 || !*s2)
{
memset(s1,'\0',size);
return(NULL);
}
char* p = strncpy(s1,s2,size);
s1[size-1] = '\0';
return(p);
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
I like C and C++, Acid Jazz, James Brown, gli Spaghetti Aglio e Olio, alla Bolognesa, alla Puttanesca e le Fettuccine alla Matriciana ('Maccaroni' over the world). Of course I like beautiful big tits girls too, my little car, Frank Zappa, the art of Zen, italian coffee and much more...