In reference to the How to write code based on the typedef? thread
I am pointing to the array element as follows:
void** text_ptr_p = l_language_Text_data_VPA[text_id];
void** text_format = text_ptr_p[0];
and sending the address to another fucntion as follows:
hmi_gfx_mgr_decode_bit_format(&text_ptr_p[index]);
and receiving as
static void hmi_gfx_mgr_decode_bit_format(UINT32 * bit_format_ref)
{
//insdie the array I am assigning as follows
Size = HmStrLngTable1[*bit_format_ref];
//now what I want to do is if the Size is equal to 31 or 0x1F then it should concatenate all the other elements in the array
if(Size == 0x1F)
{
// write ur code here
}
}
HmStrLngTable1 looks like follows:
HmStrLngTable1[]
{
/*0x000C */, 0x05, 0x4D, 0x79, 0x4B, 0x65, 0x79
/*0x0012 */, 0x1F, 0x00, 0x0C
/*0x0015 */, 0x1F, 0x00, 0x0C
}
If you see the lines marked in red which starts with 0x1F if that is the case then I need to point to the location which is given by the next two bits which are 0x00 and 0x0C after combining them which becomes 0x000C and which is in green color in the very starting line of the array. Got it.
Probably * bit_format_ref
can be used to point HmStrLngTable1
If you have any doubts get back to me?
Loading
VulpesPosted Nov 9, 2011, 10:31 AM
Karthik AgarwalPosted Nov 9, 2011, 10:34 AM
SID = n1 * 2^16 + n2 * 2^8 + n3;
Also Vulpes can you tell me a possible solution for the last post which we were discussing that UINT32 was holding a string. I have multiple data types which will be sent from another function of which one of them is hex value whose max value can be 4 bytes and the other type is string. so what can i do for this type of scenario? Possible i should end up with something by tomorrow. Hope you will come up with some possible solution.
if there is any solution then state some example how that can be implemented.
Karthik AgarwalPosted Nov 9, 2011, 10:02 AM
what are you trying to do it here rather index incrementing. if i have three hex values after 0x1F what should i do. Why are multiplying it with 256 if i have three values like n1,n2,n3 then what the multiplication factor should be. reply as soon as possible.
Karthik AgarwalPosted Nov 9, 2011, 3:34 AM
Sam HobbsPosted Nov 9, 2011, 3:02 AM
As best as I can see, about the line:
I think that Vulpes just said "I'm wondering how this line is even compiling".
I tried to explain what would happen if that code was to compile. I still doubt that it compiles. If it compiles for you then there is something you are not telling us. Are you posting from another universe?
Note that I was wrong; it is taking a while for me to get back into the C++ mode. In that call to strlen the bit_format_ref would be de-referenced by the * so that the contents of bit_format_ref would be used as an address and the data at that address would be searched.
Your latest code does not compile. The line shown above does not compile. Note that bit_format_ref is not even initialized in that code. Also concat_string is not declared. The declaration of static_string will not work; you will get compiler errors from it too.
Karthik AgarwalPosted Nov 9, 2011, 12:49 AM
I kept a break point and checked the value of the size as well, it's giving the absolute value. After working too hard yesterday night i made it working finally. But any possible issues being a bad programmer in C especially, you should be able to clear them out,
Please look at the following code:
UINT32 * bit_format_ref;
UINT8 Size;
UINT32 *temp;
UINT8 static_string[32] = {0};
UINT8 array_index = HMI_STRLEN(concat_string);
Size = strlen(*bit_format_ref);
temp = *(bit_format_ref);
sprintf(static_string, "%s", temp);
len = 0;
while(static_string[len] != '\0')
{
if(array_index <= 31)
{
concat_string[array_index++] = static_string[len++];
}
}
Sam HobbsPosted Nov 8, 2011, 7:45 PM
I am saying that I will help you in a manner that your are more likely to get when you ask for assistance in a site where there are many developers experienced with C++. Most experienced programmers would choke on the use of a UINT32* in a strlen. I truly doubt that you must do that.
A UINT32* is a pointer to a 4-byte integer. I am surprised that strlen(*bit_format_ref) compiles if bit_format_ref is a UINT32*, but I will assume that that is the declaration of bit_format_ref and the code compiles. Note that for Intel architecture processors that most Windows implementations use, integers are stored in reverse order. If bit_format_ref is a UINT32* then *bit_format_ref would be the UINT32; the 32-bit double-word. If the UINT32 has any bytes that are zero (NULL) then strlen ends there. Otherwise strlen will go through memory until it either gets a memory access violation or gets a byte with zero.
VulpesPosted Nov 8, 2011, 3:10 PM
Size = strlen(*bit_format_ref);
Given that the strlen function takes a const char* argument, I'm wondering how this line is even compiling given that it's been passed a UINT32 which is an unsigned long?
If you're trying to get the length of the bit_format_ref array, then you won't be able to do it like this.
Either you'll need to pass the length of the array as a separate parameter when you pass the array or you'll need to add a further 'null' element at the end of the array. You can then iterate through it until you get to the 'null' to calculate its length.
Before you do anything else, I'd try doing a:
printf("%d\n", Size);
to see what value is being assigned to Size. If it's not the value you're expecting, then I'd try assigning that value explicitly to Size and seeing whether it works properly then.
Karthik AgarwalPosted Nov 8, 2011, 4:24 AM
UINT32 * bit_format_ref;
UINT8 len;
UINT8 array_index;
UINT8 concat_string[];
if(bit_format == 0x01)
{
/* Static string that needs to displayed */
Size = strlen(*bit_format_ref);
for(len = 0; len < Size; len++)
{
if(array_index <= 31)
{
concat_string[array_index] = (UINT8) (bit_format_ref[len + 1]);
array_index++;
}
}
}
Note: Please respond at the earliest as i already took lot of time for this.
VulpesPosted Nov 4, 2011, 8:59 AM
However, printf and Console::WriteLine are not too dissimilar in functionality :)
Karthik AgarwalPosted Nov 4, 2011, 7:57 AM
i haven't worked on the console application previously so i was thinking that there might some syntax like console.readline() or writeline() for c language in visual studio. but i made a try with scanf and printf which worked and hence i said that i solved it. i don't want to waste your time by looking into that as i solved it.
I tried debugging that many times but couldn't succeed in finding the solution regarding the issue where i tried reading the string. i am not sure what the problem could be?
i checked type casting the data type to UINT8 as well which didn't give the desired result.
VulpesPosted Nov 4, 2011, 7:06 AM
char s[20];
printf("\nInput a string : ");
scanf("%s", &s);
printf("You entered %s", s);
int i;
printf("\nInput an integer : ");
scanf("%d", &i);
printf("You entered %d", i);
Not sure what you meant by your edit - do you mean the previous problem has now been solved?
Karthik AgarwalPosted Nov 4, 2011, 5:02 AM
//EDITED please don't try the below post this is solved it
In the mean time can you tell me how to read and write to console window.
i want to read all kinds of values actually from console window like string, char, numerical an hex values.
i want to write concat_string array finally as output.
Basically i am trying to pass arguments to the following function from console window
static void hmi_gfx_mgr_new_interface(UINT16 text_id, void * dynamic_data_vp)
{
//write code here
}
how can i do that?
Note: i should accept the arguments when i press enter and finally i should show the concatenated string.
and then it should loop again and should ask to enter arguments again (infinite loop).
VulpesPosted Nov 3, 2011, 8:19 PM
Perhaps if you could give an example, saying what the results are and what they should be, that would help to resolve it.
Karthik AgarwalPosted Nov 3, 2011, 2:31 PM
i am just trying to
I will make things simple now
I have a void pointer array as follows:
void *l_language_Text_data_VPA[] = {
l_TripResetLine3_Text_Data_VPA,
l_Dummy_Text_Data_VPA,
l_TripMenuTitle_Text_Data_VPA
};
which in turn are defined as follows:
void *l_TripResetLine3_Text_Data_VPA[4] =
{
l_TripResetLine3_Text_Format_U8A,
T_411_A,
T_411_B,
0x01
};
void *l_Dummy_Text_Data_VPA[6] =
{
l_Dummy_Text_Format_U8A,
T_438_B,
T_414_C,
"abcdefghijklmnop",
T_414_A,
0x32
};
void *l_TripMenuTitle_Text_Data_VPA[4] =
{
l_TripMenuTitle_Text_Format_U8A,
T_413_B,
T_613_B,
0x11
};
which in turn as follows:
UINT8 l_TripResetLine3_Text_Format_U8A[2] = {0x03, 0x30};
UINT8 l_Dummy_Text_Format_U8A[3] = {0x05, 0x10, 0x02};
UINT8 l_TripMenuTitle_Text_Format_U8A[2] = {0x03, 0x20};
Now I have to point to the array l_Dummy_Text_Data_VPA elements with below line
cat_string[index] = bit_format_ref[len];
in which
else if(bit_format == 0x01) // this statement is true when it's a string like "abcdefghijklmnop" as stated in l_Dummy_Text_Data_VPA
VulpesPosted Nov 3, 2011, 12:40 PM
I can't see any obvious problem with the code - whatever is at index 'len' in the bit_format_ref array will be assigned to cat_string[index].
There might be a possible conversion issue if the arrays are respectively of types UINT32 and UINT8.
Also did you intend to carry on looping after incrementing index or break from the 'for' loop at that point?
Karthik AgarwalPosted Nov 3, 2011, 12:07 PM
which i'm marking in pink color in previous post whose link is
(http://www.c-sharpcorner.com/Forums/Thread/146097/how-to-write-code-based-on-the-typedef.aspx).
possibly the pointer is causing problem.
when i try to access the string marked in red color in the above referred post with the pointer bit_format_ref.//EDITED
VulpesPosted Nov 3, 2011, 11:38 AM
Karthik AgarwalPosted Nov 3, 2011, 10:43 AM
static unsigned char const HmStrLngTable1[]
2. what ever may be the number of elements which start with 0x1F. if it starts with 0x1F then we should point to the location which is pointed by the combination of the bytes following 0x1F. //EDITED
3. and about third point they both should be combined back to back and then
HmStrLngTable1[combined value] gives the exact value in the array.
VulpesPosted Nov 3, 2011, 10:31 AM
A few queries before I try to write some code:
1. What is the exact type of the HmStrLngTable1 array? It appears to be int or unsigned int but I thought it might be one of your typedefs.
2. What happens if there is more than one element with the value 0x1F? Should those after the first still be concatenated with the other elements?
3. What exactly do you mean by concatenation? It looks like the hex representations should all be laid end to end (presumably in ascending order of array index) but should they then be converted back to a number or left as a string?