This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Strings.....


> I need a really fast way to do the following:

Please understand that this is the list for help on the GNU C
compiler, not for help with C in general. You cannot really expect
anybody on this list to implement this function for you. Please use
other fora, such as comp.lang.c, where general questions on C are
on-topic.

> char *string;
> 
> string = (char *)malloc(sizeof(char)*10);
> string = "Hello\0";

If you really meant to write this, you need to study C in more detail.
When you assign "Hello\0" to string, than the result of the earlier
allocation is lost and garbage. Also, modifying the string won't work
because it is a constant.

To copy overlapping memory, you can use the memmove(3) function.

Regards,
Martin

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]