Hey, I'm using Allegro 4.4.2 and C for a uni project, and learning the functions. I'm aware we can define a color as an int with the function makecol(r,g,b), however I could not find a version of it compatible with hexadecimal numbers, so I decided to make one.
I made two functions to serve this purpose, one is hexcol(hex), which is compatible with a hex color in a string (works with no capital letters, capital letters, numbers, with or without a # at the front).
I've had an issue sending a string into a function however, and need to copy it into a new string with a defined size. I'm wondering if there's a way to copy an array into another one, aside from string.h's strcpy(destination,source).
Here's the code, i did it in a heartbeat so I'd appreciate if anyone has any feedback on it aside from the array to array copy.
just use a pointer
Why do you need to copy it?
Reading your code, it seems a little overcomplicated. Which is fine if you understand it.
Wow, that's much more simple than i thought.
I started learning C in October, still don't completely understand pointers and I didn't learn left/right shift operations yet. That pointer method is really useful though, thank you!
Edit: I found a way to implement the pointer into the code that I understand, avoiding string.h. thank you!
pointers are just variables with values as addresses in memory.
int p;
int a[10];
int *v;
all 3 of these are pointers. The only difference is 2 are created on the stack. The other is created on the heap.
left/right shifts are just ways to multiply and divide factors of 2. It's just slightly faster. For something small like this it's trivial. Most compilers will convert it in the background anyway.
a << x is multiplying a by 2^x
a >> x is dividing a by 2^x
"c = (c << 4) + h" is the same as "c = (c * 16) + h"