You are declaring a pointer to a string.  You need to declare an array of
characters like this instead...

char string2[256];

Brian

-----Original Message-----
From: Justin Ryan [PHT] <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>; [EMAIL PROTECTED]
<[EMAIL PROTECTED]>; [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Tuesday, May 25, 1999 5:12 PM
Subject: segfault on sprintf?


>hey guys, any idea why my program would segfault whenever I try to use
>sprintf? example program I wrote to try and find my error:
>
>#include <stdio.h>
>
>int main()
>{
>char *string;
>char *string2;
>
>string = "blah";
>
>sprintf(string2, "%s is the string", string);
>
>printf("the string says %s", string2);
>
>return (0);
>}
>
>this segfaults, if i just use printf with string it works fine.. any
>input?
>
>-Justin
>
>|--------------------------------------------------
>|Justin Ryan
>|Developer Relations / Support Associate
>|Pacific HiTech / TurboLinux
>|http://www.turbolinux.com / [EMAIL PROTECTED]
>|WebMaster, PCHelp - http://computers.iwz.com
>|[EMAIL PROTECTED]
>|--------------------------------------------------
>
>---------------------------------------------------------------------------
>Send administrative requests to [EMAIL PROTECTED]
>

---------------------------------------------------------------------------
Send administrative requests to [EMAIL PROTECTED]

Reply via email to