Jump to content

Recommended Posts

Hello,

what is wrong with this code ?

PyObject * cfgGet(PyObject* poSelf, PyObject* poArgs)
{
	unsigned char bType;
	if (!PyTuple_GetByte(poArgs, 0, &bType))
		return Py_BuildException();

	char* szKey;
	if (!PyTuple_GetString(poArgs, 1, &szKey))
		return Py_BuildException();

	char* szDefault;
	if (!PyTuple_GetString(poArgs, 2, &szDefault))
		szDefault = "";

	return Py_BuildValue("s", CPythonConfig::Instance().GetString((CPythonConfig::EClassTypes) bType, szKey, szDefault).c_str());
}

 

i keep getting this error:

'=': cannot convert from 'const char [1]' to 'char *' 

because of this line here:

szDefault = "";

 

Link to comment
https://metin2.dev/topic/33180-const-char-to-char/
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

The error you are getting is self-explanatory.

String literals are constant, and you are trying to assign a pointer to a string literal to a pointer to non const which is not valid (because this would allow you to violate the const attribute of the string literal).

Link to comment
https://metin2.dev/topic/33180-const-char-to-char/#findComment-167906
Share on other sites

3 hours ago, Kuqsal said:

Try to 

szDefault = '';

i did it like that at first i left it empty i got an error to not leave it empty:

 

	char* szDefault;
	if (!PyTuple_GetString(poArgs, 2, &szDefault))
		szDefault = '0';

but i got a new error now:

a value of type "char" cannot be assigned to an entity of type "char *"
Edited by Muffins
Link to comment
https://metin2.dev/topic/33180-const-char-to-char/#findComment-167913
Share on other sites

  • Active Member
1 hour ago, Muffins said:

i did it like that at first i left it empty i got an error to not leave it empty:

 

	char* szDefault;
	if (!PyTuple_GetString(poArgs, 2, &szDefault))
		szDefault = '0';

but i got a new error now:

a value of type "char" cannot be assigned to an entity of type "char *"

Can you try szDefault ='\n';

1 hour ago, Muffins said:

ilk başta boş bıraktım gibi yaptım boş bırakmamak için bir hata aldım:

 

	
	    

ama şimdi yeni bir hatam var:

Try to this
szDefault ='\n\;
or
szDefault =NULL;

Link to comment
https://metin2.dev/topic/33180-const-char-to-char/#findComment-167917
Share on other sites

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.