Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this raw code:

BOOL							bRet, bEsisPrinter;
	BYTE							*pchTesto, *pchBuffOut;
	CHAR							chBarcode[256];
	TCHAR                           chDriverName[256], chDoc[256];
	size_t							nLenBarcode;
	int                             nbytes;
	WORD                            buffLen, *pLen;
	DWORD                           cbNeeded;
	FILE                            *fp;
	HDC                             hdc;
	HANDLE                          han;
	DEVMODE                         DM;
	DOCINFO                         infsta;
	PRINTER_INFO_2                  *pprint;


<pre>WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, szBarcode, -1, chBarcode, 256, NULL, NULL);
#else
			_tcscpy_s(chBarcode, 256, szBarcode);
#endif
			nLenBarcode = strlen(chBarcode);
		{
			nbytes = strPathZebra.size();

			if (nbytes > 0)
			{
				//pchTesto = (BYTE *)calloc(nbytes + 1, sizeof(BYTE));
				CT2A temp(cs); // convert from CString to CT2A
				pchTesto = (BYTE *)(char *)temp;
				//BYTE *p = (BYTE*)(const char*)cs;
				pchBuffOut = (BYTE *)calloc(nbytes + nLenBarcode + 3, sizeof(BYTE));
				//pchTesto = pByte;
				//nbytes = (int)fread(pchFile, sizeof(unsigned char), nbytes + 1, fp);

				if (nbytes > 0)																		// Ho letto il file testo
				{
					sprintf_s((char *)pchBuffOut + 2, nbytes + nLenBarcode + 1, (char *)pchTesto, chBarcode);





I have an error with the function sprintf_s : Incorrect format specifier

What I have tried:

I tried to search on internet but I didn't find solution..
Posted
Updated 24-May-23 0:12am

You have not included a format string in your call to sprintf_s; see sprintf_s, _sprintf_s_l, swprintf_s, _swprintf_s_l | Microsoft Learn[^].
 
Share this answer
 
Comments
Member 14594285 24-May-23 6:13am    
in place to (char*) pTesto?
Richard MacCutchan 24-May-23 7:00am    
OK, What is contained in that string?
The format specifier does not match the type of the argument you're giving to it.

Format specifier %s is used to print a null-terminated string. Your chBarcode variable is declared as a CHAR array, and pchTesto is a BYTE pointer. It seems that you want to concatenate the chBarcode string to the pchTesto string - Standard C Library/Functions/printf[^].

Try the adding '%s' to your code -
sprintf_s((char *)pchBuffOut + 2, nbytes + nLenBarcode + 1, "%s%s", (char *)pchTesto, chBarcode);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900