The fwscanf_s function doesn't read properly

Keitel 61 Reputation points
2024-04-21T11:12:33.9666667+00:00

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].name, 
    &scales[i].t,
	&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]);

    ++1;
}
fclose(shrutiliste);
}

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
C++
C++
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
    2024-04-22T07:17:23.9033333+00:00

    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 (SqlWork.com) 57,806 Reputation points
    2024-04-21T15:38:42.13+00:00

    Never mind

    0 comments No comments