please dont rip this site

Language Ccpp Cref Examples Strncpy.c

 
/****************************************************************
 * 
 * Purpose: Program to demonstrate the 'strncpy' function.
 * Author:  M J Leslie
 * Date:    03-Feb-96
 * 
 ****************************************************************/

#include <string.h>	/* strcpy */

void SafeCopy(char *Dest, int DestSize, char *Source);

main()
{
    char Text1[20]="Tracy Sorrell";		/* string buffer	*/
    char Text2[10]="Martin";       		/* string buffer	*/

    printf (" Original string contents are: %s\n", Text2);

    SafeCopy(Text2, sizeof(Text2), Text1);
  
    printf (" New string contents are: %s\n", Text2);

    strcpy(Text2, "Alex");
  
    printf (" Final string contents are: %s\n", Text2);

}

/****************************************************************/

void SafeCopy(
    char     *Dest,                   /* Destination buffer. */
    int       DestSize,
    char     *Source)                 /* Source data. */
{
  
    /* ...	Copy 'Source' into 'Dest'.
     * ...        'Dest' is padded with NULLs if 'Source' is smaller.. */
  
    strncpy(Dest, Source, DestSize);
  
    /* ...	Safety net! Add the NULL just in case 'Source' is larger
     * ...	than 'Dest'.  */
  
    Dest[DestSize-1] = '\0';
}


file: /Techref/language/ccpp/cref/EXAMPLES/strncpy.c, 1KB, , updated: 1998/3/18 10:22, local time: 2024/5/1 21:46,
TOP NEW HELP FIND: 
3.142.98.108:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://www.piclist.com/techref/language/ccpp/cref/EXAMPLES/strncpy.c"> language ccpp cref EXAMPLES strncpy</A>

Did you find what you needed?

  PICList 2024 contributors:
o List host: MIT, Site host massmind.org, Top posters @none found
- Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.
 

Welcome to www.piclist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .