From: Maik Schmidt Date: 2007-05-01T16:30:05+09:00 Subject: Re: sprintf can not work in ruby c source? In article <9d71df8a63af2a669698ea94c2a5111c@ruby-forum.com> Haoqi Haoqi wrote: > here is my simple test: > where is my mistake?? > > #include "ruby.h" > #include "stdio.h" > static VALUE > tests(){ > char *s1="a "; > char *s2=" b"; > char *buf; > sprintf(buf,"%s after %s",s1,s2); > printf(buf); > return Qnil; > } > void Init_hello(){ > rb_define_global_function("tests",tests,0); > } > I guess your problem is that buf is an uninitialized pointer pointing to an arbitrary memory location. If you declare it like this char buf[200] your program should work. -- I'm trying a new usenet client for Mac, Nemo OS X. You can download it at http://www.malcom-mac.com/nemo