C Functions

BlitzMax Forums/BlitzMax Programming/C Functions

I rewrote your code:
Strict '' Use Strict, or you'll regret it.

Import "c_func.c"
'' Don't import header files -- that doesn't work.  Nor do wildcards, if I recall correctly.

'' Putting "C" isn't neccessary as far as I've seen
Extern
'' Ptr = Your friend
	Function bprintf( num, str$z )	
	Function bsscanf( fp1:Int Ptr, str$z, a:Int Ptr, b:Intr Ptr )
	Function fopen:Int Ptr( fname$z, fmode$z )
	Function fclose( c_stream:Int Ptr )
End Extern

Type Data
	Field Name$
	Field a%
	Field b%
End Type

'' Why is that array even there?
Global DataArray:Data[]

'' Shouldn't this have been put into the array?
Local in:Data = New Data 

'' Local is your friend too.
Local fp1:Int Ptr = fopen( "test2.txt", "r" )

'' Varptr is your friend.
bsscanf( fp1, in.Name, Varptr in.a, Varptr in.b )

'' Nullify pointers so you won't accidentally use them again.
fclose( fp1 )
fp1 = Null

'' I don't know why you're printing from the array, when DataArray[1] should be Null.
Print "sscanf: " + in.Name$ + " " + in.a + " " + in.b

bprintf( in.a, in.Name$ )


I'm also compelled to mention that doing what you're doing is really, really not worth the trouble.

Edit: And before you ask, no, I didn't make sure it works, because what you're doing here is really not that good of an idea.