ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Well, I think the problem is your use of p[i], which (as you probably know), means the i'th element of array p. But because p is a void pointer, the compiler doesn't know where this element is. Each element of p could just be a single byte, or could be a structure of hundreds of bytes.
Is there some reason why you're using a void *? My advice would be to specify suitable type for this pointer (which should be the same type as two_hex_chars).
Firstly, why is p void? I'm willing to bet that whatever variable type the code is passing in is not void. Second, what type of var is two_hex_chars? Third, what is i? Where is it defined?
Not knowing what all these variables represent, I can only say that you'll need to typecast p, prior to it's dereferencing, to the type that two_hex_chars is.
If I assume that two_hex_chars is a char, then I can simply say:
He's probably writing a function that can handle a pointer to any type of data which is what a void pointer is for. i'm not sure where the index [/b]i[/b] is declared, but you can get just the first byte that p points to like this:
Originally posted by trevelluk Well, I think the problem is your use of p[i], which (as you probably know), means the i'th element of array p. But because p is a void pointer, the compiler doesn't know where this element is. Each element of p could just be a single byte, or could be a structure of hundreds of bytes.
Is there some reason why you're using a void *? My advice would be to specify suitable type for this pointer (which should be the same type as two_hex_chars).
Spot on..
What is the increment of a (void *)? who knows..
I'm just looking through the binary data converting it to hex, but I'm doing it one byte at a time.. Therefore, I've fixed it by casting it to a (char *), and can now repeatedly increment the char* pointer..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.