Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.
  1. *data = 0x0B;
  2. data++;

what is that mean? those 2 lines is written in a c program "data" is a char array and i am try to convert this program to java but assign a whole char array to one value is not possible in java at least i have to know the index. so correct me if am wrong: that mean the index 0 of that array is equal that value. data++ no clue about about it at all......

share|improve this question
stackoverflow.com –  Tachyons Mar 3 '12 at 8:50
A better place for this type of questions in StackOverflow. Please flag it appropriately, so that the moderators can migrate the question to that site. Thanks :) –  nitstorm Mar 3 '12 at 8:50
add comment

closed as off topic by Octavian Damiean, jokerdino, nitstorm, Lekensteyn, fossfreedom Mar 3 '12 at 10:41

Questions on Ask Ubuntu are expected to relate to Ubuntu within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

4 Answers

up vote 1 down vote accepted

Ok, let's start with first, so you all 3 guys understand what it actually does...
1. *data = 0x0B - there should be a declaration there of this type char *data or char data[size]. *data = 0x0B is not changing the position of the variable, it's equivalent to *(data + 0) = 0x0B which is equivalent to data[0] = 0x0B where 0x means it's a Hexadecimal number, B would be 13 in the 10-th base which in a Character form mean "ENTER". It stores in the first position of the character array a "New Line" or "Enter" press.
2. data++ means that he moves to the next position of the array, the bad thing(except if this is just a temporary data of another character array) is that he moves the pointer of the first position of the array to the next position. After data++ if you print *(data + 0) it will be equivalent to printing data[1](of the previous array) but now it moved with one position and it is actually data[0] of the new array(you can consider it as a new array).

Now tell me if this is enough information? I can't make a Java implementation without knowing what you try to do. I can try to show you the Java alternative if you want.

share|improve this answer
Ow, I saw the code lower, it is horrible. Tell me what you try to do, may be I can help. –  Lilian A. Moraru Mar 3 '12 at 9:13
its a fingerprint reader driver @Moraru Lilian –  Fathy Mar 3 '12 at 11:06
add comment

A whole char array in one value would be a String in java.

share|improve this answer
i know but am dealing with an array and at some point i have to assign this value then increment i guess. –  Fathy Mar 3 '12 at 8:40
But what are you incrementing, can you give an example ? You have a char array, are you incrementing the index of te array ? like char[i] and incrementing i ? Can this be a pointer ? –  Lucas Kauffman Mar 3 '12 at 8:46
add comment

"*data = 0x0B;" ?! It's really wired to give a pointer an arbitrary value.

In Java you can sign a string of any (reasonable) length to a single "String" variable. But in that case "data++;" is meaningless.

Can you give more context of the code ?

share|improve this answer
static void vfs301_proto_generate_0B(int subtype, unsigned char *data, int *len) { *data = 0x0B; *len = 1; data++; memset(data, 0, 39); *len += 38; data[20] = subtype; switch (subtype) { case 0x04: data[34] = 0x9F; break; case 0x05: data[34] = 0xAB; len++; break; default: assert(!"unsupported"); break; } } –  Fathy Mar 3 '12 at 8:52
@Mr.Koala: Google "pointer arithmetic" :) –  Sergey Mar 3 '12 at 9:02
add comment

Well, the question definitely does not belong to AskUbuntu... however, as a quick answer: reading one of the many articles on pointer arithmetic would clarify the matter a bit. A rough equivalent of that code in java would be

data[i] = 0x0B;
i = i + 1;  

of course, data in Java would be an array of whatever elements (chars?), not a pointer

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.