C file functions in QB64 ???
#1
I wonder if it's possible to get the C file functions working in QB64, specifically fopen, fprintf and fclose
I tried the following but it won't compile
Code: (Select All)
Type iobuf
    ptr As _Offset 'zstring ptr
    cnt As Long
    bas As _Offset 'zstring ptr
    flag As Long
    file As Long
    charbuf As Long
    bufsiz As Long
    tmpfname As _Offset 'zstring ptr
End Type

Declare Library
    Function fopen%& (file_name As String, mode As String)
    Function fclose& (file_ptr As _Offset)
    Function fprintf& (file_ptr As _Offset, frmt As String, st As String)
End Declare

Dim As _Offset fp
Dim As String fln, md, frmt, text
Dim As Long status

fln = "fopen-test.txt" + Chr$(0)
md = "w" + Chr$(0)
frmt = "%s\n" + Chr$(0)
text = "hello world" + Chr$(0)

fp = fopen(fln, md)
status = fprintf(fp, frmt, text)
Print "status = fprintf(fp, frmt, text) = "; status
status = fclose(fp)

the compiler log follows
Quote:internal\c\c_compiler\bin\c++.exe -O2 -w -std=gnu++11 -DGLEW_STATIC -DFREEGLUT_STATIC -Iinternal\c\libqb/include -Iinternal\c/parts/core/src/ -Iinternal\c/parts/core/glew/include/ -DDEPENDENCY_NO_SOCKETS -DDEPENDENCY_NO_PRINTER -DDEPENDENCY_NO_ICON -DDEPENDENCY_NO_SCREENIMAGE internal\c/qbx.cpp -c -o internal\c/qbx.o
In file included from internal\c/qbx.cpp:2333:
internal\c/../temp/main.txt: In function 'void QBMAIN(void*)':
internal\c/../temp/main.txt:29:35: error: cannot convert 'intptr_t*' {aka 'long long int*'} to 'FILE*' {aka '_iobuf*'}
  29 | *__LONG_STATUS=(  int32  )fprintf(__OFFSET_FP,(char*)(__STRING_FRMT)->chr,(char*)(__STRING_TEXT)->chr);
      |                                  ^~~~~~~~~~~
      |                                  |
      |                                  intptr_t* {aka long long int*}
In file included from internal\c\libqb/include/audio.h:21,
                from internal\c/qbx.cpp:1:
D:/QB64pe-3.6.0+/internal/c/c_compiler/x86_64-w64-mingw32/include/stdio.h:357:20: note:  initializing argument 1 of 'int fprintf(FILE*, const char*, ...)'
  357 | int fprintf (FILE *__stream, const char *__format, ...)
      |              ~~~~~~^~~~~~~~
internal\c/../temp/main.txt:48:34: error: cannot convert 'intptr_t*' {aka 'long long int*'} to 'FILE*' {aka '_iobuf*'}
  48 | *__LONG_STATUS=(  int32  )fclose(__OFFSET_FP);
      |                                  ^~~~~~~~~~~
      |                                  |
      |                                  intptr_t* {aka long long int*}
D:/QB64pe-3.6.0+/internal/c/c_compiler/x86_64-w64-mingw32/include/stdio.h:615:28: note:  initializing argument 1 of 'int fclose(FILE*)'
  615 |  int __cdecl fclose(FILE *_File);
      |                      ~~~~~~^~~~~
mingw32-make: *** [Makefile:410: internal\c/qbx.o] Error 1

I know that QB64 has file functions but I have a reason to want the C file functions

<edit>
fopen works, it's the other two functions that fail
Reply


Messages In This Thread
C file functions in QB64 ??? - by Jack - 04-26-2023, 11:00 AM
RE: C file functions in QB64 ??? - by Jack - 04-26-2023, 11:34 AM
RE: C file functions in QB64 ??? - by DSMan195276 - 04-26-2023, 01:16 PM
RE: C file functions in QB64 ??? - by Petr - 04-26-2023, 01:25 PM
RE: C file functions in QB64 ??? - by Jack - 04-26-2023, 02:25 PM
RE: C file functions in QB64 ??? - by Kernelpanic - 04-28-2023, 05:02 PM
RE: C file functions in QB64 ??? - by Jack - 04-28-2023, 05:51 PM
RE: C file functions in QB64 ??? - by Jack - 04-28-2023, 06:50 PM
RE: C file functions in QB64 ??? - by Ultraman - 04-28-2023, 07:04 PM
RE: C file functions in QB64 ??? - by Kernelpanic - 04-28-2023, 07:50 PM
RE: C file functions in QB64 ??? - by DSMan195276 - 04-29-2023, 02:16 AM
RE: C file functions in QB64 ??? - by Kernelpanic - 04-29-2023, 06:58 PM



Users browsing this thread: 4 Guest(s)