Mailinglist Archive: opensuse-de (3324 mails)

< Previous Next >
Re: GNU C: strcpy
  • From: martin.jacobs@xxxxxxxxxx (Martin Jacobs)
  • Date: Mon Feb 01 20:44:41 1999
  • Message-id: <m107QD4-0011iBC@xxxxxxxxxxxxxxxxxxxxx>



Hallo Frank,


[SuSE 5.3, 2.0.36]

Ich habe einen Pointer
char *t;

diesem weise ich Speicher zu:
t = (char *) malloc(80);

Wenn ich jetzt mit
strcpy("hallo", t);

Siehe man strcpy

Du verwechselst Quelle und Ziel:

Richtig wäre:
strcpy(t, "hallo"); /* analog t="Hallo" */

etwas hineinschreiben will, bekomme ich einen segmentation fault.

Mit
sprintf(t, "", "hallo");
gibt es keine Probleme.

...

Martin


--
Martin Jacobs * Windsbach * 100.179370@xxxxxxxxxxxxx und
martin.jacobs@xxxxxxxxxx
Registered Linux User #87175
--
Um aus der Liste ausgetragen zu werden, eine Mail an majordomo@xxxxxxxx
schicken, mit dem Text: unsubscribe suse-linux


< Previous Next >
References