UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C
  • » a strcpy && malloc

#1 2007-11-10 03:47 PM

zhn636
Member
Registered: 2007-04-24
Posts: 146

Re: a strcpy && malloc

can anyone tell me what are the differences between these code below?

char *a=(char*)malloc(10);
    a="test"

 

strcpy(a,"test")

Offline

#2 2007-11-10 04:56 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: a strcpy && malloc

The first one leaks memory, because the pointer value of 'a' is updated, not the memory it points to.

Offline

  • Index
  • » C
  • » a strcpy && malloc

Board footer

Powered by FluxBB