TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Peter Leschev
from: Frank Adam
date: 1996-07-10 15:51:00
subject: Memcopy

G'Day Peter,
 
-=> Quoting Peter Leschev to All <=-
 PL> I was wondering if there was a function similar to memcpy but
 PL> copys data only if the certain char of the dest. is set to 0. I can't
Whatever for ??? 
Not that i know of, even Borland doesn't have anything that would check 
the destination before copying to it.

Could try this..
Beware, not tested code..

main()
{
 char *s = "Hello";
 char s1[] = "fjf\0kg";
 char *s2;
 s2 = copymem(s1,s,3);
 if(s2 == NULL) printf("copy failed");
 else printf("copy succesful: %s",s2);
 return 0;
 }

char* copymem(char *dest,char *srce,int chkbyte)
{
 if(!dest[chkbyte]) memcpy(dest,srce,strlen(srce));
  else return NULL;
 return dest;                                
 }
 
Something like this ??

Or if you want to copy to where the 0 is, if it's a string strcat() will
do it,as the 0 is the end of the string, otherwise : 

dest = strchr(dest,'\0'); 
 if(!dest) return NULL;
do some calculating to make sure it fits...
memcpy(dest,srce,len);   

If this is still not what you want.. then i'm lost.
                         
  L8r Frank (fadam{at}ozemail.com.au).
                                 
___ Blue Wave/DOS v2.21
  

--- Maximus 3.01
* Origin: The Software Parlour (3:635/544)
SEEN-BY: 50/99 620/243 623/630 632/349 635/503 544 727 711/401 409 410 413
SEEN-BY: 711/430 808 809 932 934 712/515 713/888 714/906 800/1
@PATH: 635/544 50/99 711/808 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.