I am writing a simple serialization using the format L"79349 Dexter 03 05"
(Assume that the Dexter
part will be always 1 word.)
This string is to be read into 3 int
s and a wchar_t
array
I currently have the following code:
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main()
{
int id=-1,season=-1,episode=-1;
wchar_t name[128];
swscanf_s(L"79349 Dexter 03 05", L"%d %ls %d %d", &id, name, &season, &episode);
wcout << "id is " << id << endl;
wcout << "name is " << wstring(name) << endl; //wprintf(L"name is %ls",name);
wcout << "season is " << season << endl;
wcout << "episode is " << episode << endl;
}
The code above is compiled(in VS '13) without a problem, however, when executed it crashes. Using the debug option I get the message: Unhandled exception at 0xFEFEFEFE in test3.exe: 0xC0000005: Access violation executing location 0xFEFEFEFE.
By omitting some parts, I find out that this problem is occured when reading into name
.
e.g The following works just fine:
swscanf_s(L"79349 Dexter 03 05", L"%d %*ls %d %d", &id, &season, &episode);
What am i doing wrong?
My guess is that I am missing something simple and trivial but cannot find out on my own. Thanks in advance.