Hi Ken and TK Chia,
fmemopen looks very good, but sadly not available in Watcom. This is not
a big problem, rewriting the code to use buffers is not that much work.
I am using a own putc/puts-function-pair, which directly writes to video
memory. This lets me easily change it to another data source. I "saved"
fmemopen to my list of things to remember for future projects.
I will implement it similar to this:
int number;
char linebuf[81];
number = preload("filename.txt");
...
while(get_line_from_buffer(number, &linebuf, 81) != NULL) {
do_something();
}
I'll havea look at fgets how this one is storing the position in file
and do it this way. I assume it is a static or global variable keeping
track of position. I had a look at different fmemopen implementations
and there's a lot of stuff I do not totally understand...
Thank you very much to both of you!
Nils
On 1/9/19 3:35 PM, TK Chia wrote:
Hello Nils, hello Ken,
ptr_array[0] = malloc(size_of_textfile);
copy_to(file0, ptr_array[0];
ptr_array[1] = malloc(size_of_textfile);
copy_to(file1, ptr_array[1];
...
Can I still use fgets() on these pointers once the file has been loaded
there?
No, fgets wants a FILE *, which is a pointer to a stream, not a char *.
If you are not able to rewrite the program to process the buffer
directly, forgetting about fgets(), there is fmemopen() which returns a
FILE * given a string. But it may not be implemented in your C library.
https://pubs.opengroup.org/onlinepubs/9699919799/functions/fmemopen.html
I just found that the Newlib library as included in the gcc-ia16
toolchain does happen to implement fmemopen( ) (and several other
POSIX functions as well).
However, Open Watcom's C library does not have this function.
I suppose, if a `FILE *' is not absolutely needed, then one can use
strchr( ), strcspn( ), etc. to slice the input up into separate lines,
without writing a lot of code.
Thank you!
_______________________________________________
Freedos-user mailing list
Freedos-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-user