how do i return a non constant int when i just use int it gives me an error case label does not reduce to an integer constant here is the portion of the code im have issues with
DLLIMPORT int code (const char s)
{
switch ( s )
{
case "string1":
return 1;
break;
case "string2":
return 2;
break;
default:
return 0;
break;
}
}
If you mean something like a local variable, you just have to declare it first.
int result = 0;
/* your code here */
return result;
im trying to send it a string and have it return a number back using the switch statement but since the integer is non constant then it gives me an error
edit i just figured out my problem the switch statement only works on integers and i was trying to use it on a string will just use the if statement then
Oh, right. ._. I forgot that, too. ._.;
ok now my dll will not accept a parameter here is the method
DLLIMPORT int code (char s[20])
{
if (s == "string1"){return 1;}
if (s == "string2"){return 2;}
return 0;
}
and im calling it like this
s = Win32API.new('Project1','code','S','I')
s.call('string1')
To compare two strings in C you have to use strcmp (string.h) or a similiar function. It returns zero when both strings are identical.
DLLIMPORT int code (char s[]) {
if (!strcmp(s, "string1")) return 1;
if (!strcmp(s, "string2")) return 2;
return 0;
}
Notice the removed 20. Strings in C aren't easy to handle as in other languages. And are you sure about the
'S'? If you use the RGSS it has to be
'P'.
it was p thx
edit it fully works now thx