i have come across this while converting some stuff from C
how do i convert this to Aurora? And what does this actually mean? Im not understanding the math with letters ???
c = c - "a" + 26;
Lewis
Got me. I have a C compiler that came with a book on the subject and it won't compile this line.
In C, string literals are pointers to null-terminated char arrays, so that really doesn't make sense. Are you sure that it wasn't really this:
c = c - 'a' + 26;
The single quotes make a big difference, since that represents the single character 'a' with an ASCII value of 97. That would get promoted to an integer, so what you would really have there is:
c = c - 97 + 26;
And we have ASC and CHR$ for such manipulations.
The entire string library is identical to IBasic's.
Yes sorry it was with the single quotes. I just converted the whole thing before i tried to compile it. So all i have to do is use ASC then.
Thanks everyone.
Lewis
this is what i was trying to convert. It still doesnt seem to be working though. Im not sure what it should convert to in aurora. I dont think im doing it right
#define decode(c) if(c >= 'A' && c <= 'Z') c = c - 'A'; \
else if(c >= 'a' && c <= 'z') c = c - 'a' + 26; \
else if(c >= '0' && c <= '9') c = c - '0' + 52; \
else if(c == '+') c = 62; \
else if(c == '/') c = 63; \
else c = 0; \
I tried to make it into a function but from what i can see my function gets all the way to the last compare statement so all the rest are returning false. I must have done something wrong.
Anyone help me out here?
Lewis
Ah... macros...
You have to make a subroutine since Aurora doesn't support macros:
sub decode(byte c byref)
{
if (c >= asc("A") and c <= asc("Z")) c = c - asc("A");
else if (c >= asc("a") and c <= asc("z")) c = c - asc("a") + 26;
else if (c >= asc("0") and c <= asc("9")) c = c - asc("0") + 52;
else if (c = asc("+")) c = 62;
else if (c = asc("/")) c = 63;
else c = 0;
}
yeh im prety sure my attempt looked exactly the same as yours Parker, maybe i missed something small but important out. Ill give it a try.
Lewis
He He. You didnt try it did you Parker ;)
File: C:\Documents and Settings\Lewis *******\Desktop\Decode.src (3217) syntax error - else
File: C:\Documents and Settings\Lewis *******\Desktop\Decode.src (3219) syntax error - else
File: C:\Documents and Settings\Lewis *******\Desktop\Decode.src (3221) syntax error - else
File: C:\Documents and Settings\Lewis *******\Desktop\Decode.src (3223) syntax error - else
File: C:\Documents and Settings\Lewis *******\Desktop\Decode.src (3225) syntax error - else
Lewis
Nope, I didn't. But just add braces around each condition and it should work.
sub decode(byte c byref)
{
if (c >= asc("A") and c <= asc("Z")) {c = c - asc("A");}
else if (c >= asc("a") and c <= asc("z")) {c = c - asc("a") + 26;}
else if (c >= asc("0") and c <= asc("9")) {c = c - asc("0") + 52;}
else if (c = asc("+")) {c = 62;}
else if (c = asc("/")) {c = 63;}
else {c = 0;}
}
Yeh i did it. Just thought i would let you know. lol.
Lewis