I'm guessing that you need to change

ccall(:sscanf, Int32, (Ptr{Uint8}, Ptr{Uint8}, Ptr{Int32}, Ptr{Int32}, 
Ptr{Uint8}),
 "12:30 AM", "%d:%d %s", hour, minutes, ampm)

to 

ccall(:sscanf, Int32, (Ptr{Uint8}, Ptr{Uint8}, Ptr{Int32}, Ptr{Int32}, 
Ptr{Uint8}),
 "12:30 AM", "%d:%d %s", &hour, &minutes, &ampm)

But am not totally sure.

 -- John

On Feb 21, 2014, at 3:29 PM, Helios De Rosario <[email protected]> 
wrote:

> Hello,
> 
> This is my first post in this group. Please correct me if I make some mistake 
> in asking my question. (I have not found any specific "posting guide" for 
> this group.)
> 
> I'm accustomed to use sscanf in C and Octave, and it is one of the first 
> things that I missed when started using Julia. I'm not sure of the reason why 
> it is not implemented (on the other hand there is the @sprintf macro). Of 
> course, regular expressions can do that work as well, and perhaps Julia 
> developers have reasons to prefer that option to a scanf-like function. But I 
> have not found any statement about this topic in the manual, this group or 
> anywhere else.
> 
> Ok, be that as it may... I tried to call the C function sscanf with ccall (at 
> least for fun, if not for practical reasons), but I have not been able to 
> make it work to scan float variables. For example, this does work (using int 
> and string variables):
> 
> ## C equivalent code:
> # int hour, minutes;
> # char ampm[3];
> # sscanf("12:30 AM", "%d:%d %s", &hour, &minutes, ampm);
> 
> hour = Int32[0]
> minutes = Int32[0]
> ampm = "??"
> ccall(:sscanf, Int32, (Ptr{Uint8}, Ptr{Uint8}, Ptr{Int32}, Ptr{Int32}, 
> Ptr{Uint8}),
>  "12:30 AM", "%d:%d %s", hour, minutes, ampm)
> 
> However, if I want to scan a float, sscanf fails to parse the string. E.g. 
> replace "hour" or "minutes" by a Float64 - or Float32 - array, and change the 
> corresponding "%d" in the pattern string by "%f", "%g", "%e", etc.; in that 
> case ccall returns 0, and the variables do not change.
> 
> Any idea of why?
> I'm using Julia 0.2.1 for Windows 32 bit in Windows 7. Please let me know if 
> you need more details.
> 
> By the way, you will see in the example that in the first argument to ccall I 
> have only put the name of the C function, instead of a tuple including the 
> name of the C library ("stdio" in this case). The reason is that using the 
> tuple throws an error ("error compiling anonymous: could not load module 
> stdio: no error"). Does it anything to do with my not having MinGW or any 
> other compiler installed in my machine?

Reply via email to