Qbasicnews.com
Allegro help with []'s - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: Qbasic "like" compilers/interpreters (http://qbasicnews.com/newforum/forum-5.html)
+--- Forum: FB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-15.html)
+---- Forum: FB Projects (http://qbasicnews.com/newforum/forum-16.html)
+---- Thread: Allegro help with []'s (/thread-6084.html)



Allegro help with []'s - Jotz - 02-16-2005

I need to create several bitmaps in Allegro, but declaring all of them seperately would take forever. How could I use the []'s in bitmap pointers? Example:

DIM pic[256] AS BITMAP ptr

It comes up with an error because of the []'s. I have seen them used in the starfields demo for allegro. How could I use those?


Allegro help with []'s - adosorken - 02-16-2005

Might wanna try using () instead of []. [] has another purpose in FB. You can't directly port C code to FB.


Allegro help with []'s - v3cz0r - 02-16-2005

[]'s are only used for pointer indexing, () should be used to declare and access arrays, array[idx] is a shortcut for *(array + idx).


Allegro help with []'s - BastetFurry - 02-16-2005

Quote:[]'s are only used for pointer indexing, () should be used to declare and access arrays, array[idx] is a shortcut for *(array + idx).

If i understand you right i can declare the following:
dim shared somestring as string ptr
and retrive singel chars out of it thne c way?
eg.: sometring[4] = mid$(somestring,4,1)

So Long, The Werelion!


Allegro help with []'s - v3cz0r - 02-16-2005

Nope, STRING is actually a descriptor, [] will access the descriptor, not the data, but you could do:

Code:
    dim shared somestring as byte ptr
    
    somestring = strptr("abc")
    
    i = 0
    do while somestring[i] <> 0
        print chr$( somestring[i] );
        i = i + 1
    loop