C Functions

BlitzMax Forums/BlitzMax Programming/C Functions

I'm finally moving from being an observer to using my copy of BlitzMax. As a consequence this inquiry has a bit more substance.

Given the following text file (test2.txt),

blah1 8 12
blah2 3 7


I would like to read it with a set of C functions (func.c)

#include<stdio.h>
#include<stdlib.h>


void bprintf(int a, char *name)
{
	printf("%d, %s", a, name);
}

int bsscanf(FILE *fp1, char *name, int *a, int *b)
{
	char buf[120];
	int i = 0;
	while(fgets(buf, sizeof(buf), fp1) !=NULL)
	{
	if (sscanf(buf, "%s %d %d", &name[i], &a[i], &b[i]) !=3)
	{
	}
	i++;
	}

	return i;
}


void bfprintf(FILE *fp1, int index, int a, char *name)
{
	fprintf(fp1, "%d, %s", a, name);
}





However, it doesn't appear to work with the following (incorrect) BlitzMax code (read.bmx),


Import "c_func.c"
Import "include/*.h"


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


Extern "c"
	Function bprintf(num, str$z)	
	Function bsscanf(fp1, str$z, a, b)
	Function fopen(fname$z, fmode$z)="fopen"
	Function fclose(c_stream)="fclose"
End Extern

	
	
Global DataArray:Data[]
Local in:Data = New Data 


fp1 = fopen("test2.txt", "r")
bsscanf(fp1, in.Name, in.a, in.b)
fclose(fp1)

Print "sscanf: " + DataArray[1].Name$ + " " + DataArray[1].a + " " + DataArray[1].b

bprintf(DataArray[1].a, DataArray[1].Name$)




Any corrections would be much appreciated. On the surface and some other experimentation it appears that I will in time be able to make use of a mix of BlitzMax and C...