The fwscanf_s function doesn't read properly

Keitel 61 Reputation points

I have a program in C that have been working fine since I compiled it in an earlier version of Visual Express. Now that I have been compiling it in Visual Studio 2022, the fwscanf_s function doesn't work properly. It reads text and integers. The integers are displayed properly, but not the text variable.

struct svaras
		TCHAR name[20];
		int t;
		int rk[2];	
		int rk2[2];
		int rs[2];
		int rs2[2];
	struct svaras scales[150];

i = 0;

if(_waccess_s(L"shrutilist.dat", 0) != -1){
	Receivedata = GetModuleFileName(NULL, Buffer, MAX_PATH);		
	PathCchRemoveFileSpec(Buffer, MAX_PATH);				
	PathCchAppend(Buffer, MAX_PATH, L"shrutilist.dat");				
	err = _wfopen_s(&shrutiliste, Buffer, L"r");

while (i < 60) {

    test = fwscanf_s(shrutiliste, "%20ls  %i %i %i  %i %i \n",  					

	&scales[i].rk[0], &scales[i].rk[1],
	&scales[i].rk2[0], &scales[i].rk2[1],
	&scales[i].rs[0], &scales[i].rs[1],
	&scales[i].rs2[0], &scales[i].rs2[1]);


The variable scales[i].name shows this in the debugger:

{name=0x006fb9fc L"쳌쳌쳌쳌쳌쳌쳌쳌쳌쳌쳌쳌쳌쳌쳌쳌쳌쳌쳌쳌... t=-858993460 rk=0x006fba28 {-858993460, -858993460}

While when it is displayed in a list box, it only shows this: 쳌쳌쳌쳌쳌쳌쳌쳌쳌

The integers are displayed correctly in the list box.

Thanks in advance.

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,801 questions
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,561 questions
{count} votes

Accepted answer
  1. Minxin Yu 10,361 Reputation points Microsoft Vendor

    Hi, @Keitel

    Use L"" in fwscanf_s(shrutiliste, "%20ls %i %i %i %i %i \n",

    fwscanf_s(shrutiliste, L"%20ls %i %i %i %i %i \n",

    And as Viorel said, the format should be
    L"%20ls %i ...", scales[i].name, 20, &scales[i].t,...

    Best regards,

    Minxin Yu

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Bruce ( 57,806 Reputation points

    Never mind

    0 comments No comments