please dont rip this site

Language Ccpp Cref Examples Strcpy.c

/ *
 * Purpose: Program to demonstrate the 'strcpy' function.
 * Author:  M J Leslie
 * Date:    12-Mar-94
*/

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

main()
{
  char text1[10]="martin";		/* string buffer	*/
  char text2[20]="leslie";		/* string buffer	*/

  printf (" original string contents are: %s\n", text1);
					/* Copy text2 into text1. 
					   If text1 is smaller that text2
					   it will probably overwrite
					   something!		*/
  //strcpy(text1, text2); //unsafe.
  *text1 = 0; //should check that sizeof(text1)>0
  strncat(text1, text2, sizeof(text1)); //safer. 
  printf (" new string contents are: %s\n", text1);

  strcpy(text1, "linux is picky about its friends"); //this does not end well.
  printf (" final string contents are: %s\n", text1);

}


file: /Techref/language/ccpp/cref/EXAMPLES/strcpy.c, 0KB, , updated: 2018/3/2 14:13, local time: 2024/5/4 15:50,
TOP NEW HELP FIND: 
3.149.233.72: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/strcpy.c"> language ccpp cref EXAMPLES strcpy</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!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .