May 17, 2024, 06:45:57 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Converting C

Started by Zen, January 22, 2006, 11:14:47 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zen

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

Bruce Peaslee

Got me. I have a C compiler that came with a book on the subject and it won't compile this line.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Mike Stefanik

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;

Mike Stefanik
www.catalyst.com
Catalyst Development Corporation

Ionic Wind Support Team

And we have ASC and CHR$ for such manipulations. 

The entire string library is identical to IBasic's.
Ionic Wind Support Team

Zen

January 22, 2006, 12:51:14 PM #4 Last Edit: January 22, 2006, 01:15:40 PM by Lewis
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

Zen

January 22, 2006, 01:13:13 PM #5 Last Edit: January 22, 2006, 01:16:15 PM by 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

Parker

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;
}

Zen

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

Zen

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

Parker

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;}
}

Zen

Yeh i did it. Just thought i would let you know. lol.

Lewis