Nothing seems to be working. :'(
Printable View
I'd use open_wmemstream() to create a wide-character memory stream, then fputws() a multi-line constant wide-character string into it (say static const wchar_t my_test_stream[] = L"First line\nSecond line\nThird line\n"; ). Then rewind(handle) and you can give the handle to fgetws(). This is POSIX.1-2008, so I don't know if you can use it in Windows.
look at this thread for better understanding of the problem
http://cboard.cprogramming.com/c-pro...pe-syntax.html
Consider the following example code:
It shows how to create a FILE * handle to wide-character in-memory data. Then I stuff wide-character strings into it, the example data I wish to test. Then I rewind() the stream. Now I can use fgetws() to read the data back from the stream.Code:#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>
int main(void)
{
FILE *handle;
wchar_t *cache_ptr = NULL;
size_t cache_len = 0;
wchar_t line_buffer[1024];
wchar_t *line;
/* Create the memory stream */
handle = open_wmemstream(&cache_ptr, &cache_len);
if (!handle) {
fprintf(stderr, "Cannot create a wide-character memory stream.\n");
return 1;
}
/* Stuff data into the memory stream */
if (fputws(L"First line\nSecond line\nThird line is the last one\n", handle) == -1) {
fprintf(stderr, "Error writing to the wide-character memory stream.\n");
return 1;
}
/* Rewind the memory stream, so we can read from it */
rewind(handle);
/* Your fgetws() function goes here -- this reads each line */
while (1) {
line = fgetws(line_buffer, sizeof line_buffer, handle);
if (!line)
break;
printf("Read %d wide characters\n", (int)wcslen(line));
}
/* Close the handle normally */
if (fclose(handle)) {
fprintf(stderr, "Error closing wide-character memory stream.\n");
return 1;
}
/* Discard the buffer. */
free(cache_ptr);
cache_ptr = NULL;
cache_len = 0;
return 0;
}
Quote:
Originally Posted by Linked_List
I didn't ask if you could get it working, I asked if it sounded like the function that you needed.
Quote:
Originally Posted by Linked_List
http://cboard.cprogramming.com/c-pro...pe-syntax.html
Where did you get this code from? I'm guessing that you didn't write it because you asked for an explanation of what it means in the other topic