strcpy

Stelios Bounanos sb at dial.pipex.com
Wed Apr 26 02:57:57 EEST 2000


In message <390578E6.E3BA59B6 at yahoo.com> , 
"L.O.V.E." <mirror_92 at yahoo.com>  was rumoured to have said about 
`` strcpy '': 

> Gia sas.
> To programma pu akoloy8ei einai ena APLO programa pu perigrafei thn
> strcpy synartisi.
> Mou typwnei kanonika to output, OMWS mou dimioyrgei  panta core, opos
> blepete sto telos :
> Giati ayto ?
> 
> 
> #include <stdlib.h>
> #include <stdio.h>
> #include <string.h>
> 
> char source[]="the source string";
> 
> int main()
> {
>  char dest1[80];
>  char *dest2, *dest3;
> 
> printf("\n source: %s", source);
> 
> strcpy(dest1, source);

Genika 8a htan kalytero na xrhsimopoieis thn strncpy. Se
anagkazei na skeftesai ti kai posa antigrafeis.

> printf ("\n dest: %s", dest1);
> 
> dest2=(char *)malloc(strlen(source)+1);
> strcpy(dest2, source);
> printf("\n dest2: %s\n", dest2);
> 
> strcpy(dest3, source);

E, poy einai h malloc gia to dest3?

> free(dest2);

To an krasarei giati prospa8eis na grapseis se mnhmh poy de soy anhkei
'h giati prospa8eis na kaneis free mnhmh poy den ekanes malloc einai
mia endiaferoysa erwthsh :>

> free(dest3);
> 
> return 0;
> }
> 
> output:
> ------------
> source : the source string
> dest1:  the source string
> dest2 :  the source string
> Segmatation fault(core dumped)
> 
> [natalia at localhost~]$
> 

Elpizw ayta na ta grafeis gia ekpaideytikoys skopoys. Gia pio sobares
douleies des to string class ths C++ poy se prostateyei apo polla tetoia
la8h kai exei operations me ta opoia glitwneis poly xrono kai kwdika.

Rgds,
sb.



--
linux-greek-users mailing list -- http://lists.hellug.gr




More information about the Linux-greek-users mailing list