swscanf_s White Space Help
-
Hello, A wchar_t array contains two sentences inside which I need to save in two separate variables.
wchar_t str[] = L"'This is the first sentence' 'This is the second sentence'";
I want to split in a way that first sentence and second sentence equals to these:
wchar_t first_sentence[MAX_PATH]=L"'This is the first sentence'";
wchar_t second_sentence[MAX_PATH]=L"'This is the second sentence'";I am using below code but it does not work as expected.
#include "stdafx.h"
#include <wchar.h>
#include <windows.h>
#include <stdio.h>int _tmain(int argc, _TCHAR* argv[])
{
wchar_t str[] = L"'This is the first sentence' 'This is the second sentence'";wchar\_t first\_sentence\[MAX\_PATH\]; wchar\_t second\_sentence\[MAX\_PATH\]; swscanf\_s(str, L"'%s' '%s'", first\_sentence, \_countof(first\_sentence), second\_sentence, \_countof(second\_sentence)); printf("first\_sentence=%ls\\nsecond\_sentence=%ls\\n", first\_sentence, second\_sentence); system("PAUSE"); return 0;
}
As far as I understand swscanf_s is pausing when it encountes the first white space. How am I suppose to get whole string between single quotes with swscanf_s please?
-
Hello, A wchar_t array contains two sentences inside which I need to save in two separate variables.
wchar_t str[] = L"'This is the first sentence' 'This is the second sentence'";
I want to split in a way that first sentence and second sentence equals to these:
wchar_t first_sentence[MAX_PATH]=L"'This is the first sentence'";
wchar_t second_sentence[MAX_PATH]=L"'This is the second sentence'";I am using below code but it does not work as expected.
#include "stdafx.h"
#include <wchar.h>
#include <windows.h>
#include <stdio.h>int _tmain(int argc, _TCHAR* argv[])
{
wchar_t str[] = L"'This is the first sentence' 'This is the second sentence'";wchar\_t first\_sentence\[MAX\_PATH\]; wchar\_t second\_sentence\[MAX\_PATH\]; swscanf\_s(str, L"'%s' '%s'", first\_sentence, \_countof(first\_sentence), second\_sentence, \_countof(second\_sentence)); printf("first\_sentence=%ls\\nsecond\_sentence=%ls\\n", first\_sentence, second\_sentence); system("PAUSE"); return 0;
}
As far as I understand swscanf_s is pausing when it encountes the first white space. How am I suppose to get whole string between single quotes with swscanf_s please?
-
Thank you very much for your help. Works great. One more question please. How can I select all the characters till to a specific word? Say, I want to select all characters till "the" word? I tried
%[^(the)]
but to no avail. Cheers
Even if that worked, it probably wouldn't do what you wanted - e.g. if the input text was "a small withered man with the axe", you'd get "a small wi" copied to your output variable. Depending on what you're trying to do, maybe regex() might be a better tool in this case, though I'm not sure about regex() and wide strings.
-
Even if that worked, it probably wouldn't do what you wanted - e.g. if the input text was "a small withered man with the axe", you'd get "a small wi" copied to your output variable. Depending on what you're trying to do, maybe regex() might be a better tool in this case, though I'm not sure about regex() and wide strings.