The function I am writing right now will return already a zero
terminated string.
I dont know how to do it without a 0-termination. Maybe with length
variables? Not good...
A DOS line ends with 0x0D 0x0A, my function "cuts" this by overwriting
the 0x0D with a 0. Otherwise I cant use string functions and have to
keep track of string length in a variable.
Thanks!
Nils
On 1/10/19 8:10 AM, Ken Yap wrote:
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!
Whether you use fmemopen() later or roll your own text digestion code,
you should make sure to terminate the text read in with a NUL character
so that it's a standard C string, otherwise the string functions will
run amok.
char *buffer = malloc(size + 1);
status = read_data(file, buffer, size);
if (status == GOOD) {
buffer[size] = '\0';
process_buffer(buffer);
} else {
...
}
I would digest the text into an internal representation just after the
file is read, but that's just me.
Ken
_______________________________________________
Freedos-user mailing list
Freedos-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-user
_______________________________________________
Freedos-user mailing list
Freedos-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-user