# Ruby windows extension printf/scanf crash, but fgetc/fputc o

**URL:** <https://www.ruby-forum.com/t/ruby-windows-extension-printf-scanf-crash-but-fgetc-fputc-o/78554>\
**Category:** Ruby\
**Created:** [December 6, 2006, 8:39pm UTC](https://www.ruby-forum.com/t/ruby-windows-extension-printf-scanf-crash-but-fgetc-fputc-o/78554 "2006-12-06T20:39:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Maycock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9a140/32.png) [@Matt\_Maycock](https://www.ruby-forum.com/u/Matt_Maycock)\
**Post date:** [December 6, 2006, 8:39pm UTC](https://www.ruby-forum.com/t/ruby-windows-extension-printf-scanf-crash-but-fgetc-fputc-o/78554/1 "2006-12-06T20:39:53Z")

</div>

Greetings,

I have a ruby extension I wrote a ruby extension that runs perfectly  
well on my OS X Tiger Box, but when I try to compile it for windows  
via  
[http://www.koontzfamily.org/david/blog/?p=230](http://www.koontzfamily.org/david/blog/?p=230)

I run into some issues. One of which is that when I have a FILE \*  
that I got from this macro I wrote:  
#define GRAB\_FILE(a) (RFILE(a)-\>fptr-\>f)  
I run into issues with fscanf and fprintf. For fscanf, there is a  
windows message dialog saying  
“The exception unknown software exception (0xc0000008) occurred in  
the application at location 0x77fac57c” … click ok to terminate,  
cancel to debug (I know, not entirely useful, jsut explaining exactly  
what happened).

For fprintf, I get  
bouts\_intervals.rb:250: [BUG] Segmentation fault  
ruby 1.8.4 (2006-04-14) [i386-mswin32]

ie just a seg-fault.

The offending fprintf code (this is the unexpanded macro version):  
fprintf(out,   
“/\* Automatically Generated C Program to run Bouts List Analysis.  
\*/” “\n”   
“\n”   
“#include "%s"” “\n”   
“\n”   
“\n”,   
name##\_report);  
fputc works perfectly well.

the offending fscanf code is:  
long reading = 0;

while (1) {  
switch (fscanf(channel, “%ld”, &reading)) {  
BUT note that fgetc works perfectly well on channel, and returns the  
data in the file accurately (note that fscanf has also been used

The ruby headers do seem to replace fputc and fgetc – but why not  
fprintf / fscanf? Is there anything I can do to fix these?

~Matthew Maycock
