Apologies if my following question sounds trivial but I'm struggling with the fundamental concept of "converting an a char array to a string" for use in the method strstr().
Essentially I have an array called EUI_only[] which is dynamically populated at a certain stage of my program i.e.
EUI_only[0] = A;
EUI_only[1] = B;
EUI_only[2] = C;
EUI_only[3] = D;
EUI_only[4] = E;
I declared EUI_only as follows at the top of my program:
char EUI_only[];
I can confirm that EUI_only[] is successfully populated as justbefore I use it in method strstr() I print it out.
Now I have the second array called receive_key_press_temporary_analysis_buffer which I intend on utilising in my strstr() i.e. the array which contains characters similar to those in EUI_only.
This array is also dynamically populated in a certain point of my program and I can confirm that the contents of the array are intact just before I use it in strstr() as I've printed this array.
Content of this array called receive_key_press_temporary_analysis_buffer can be seen below:
receive_key_press_temporary_analysis_buffer[0] = 1;
receive_key_press_temporary_analysis_buffer[1] = 2;
receive_key_press_temporary_analysis_buffer[2] = C;
receive_key_press_temporary_analysis_buffer[3] = A;
receive_key_press_temporary_analysis_buffer[4] = B;
receive_key_press_temporary_analysis_buffer[5] = C;
receive_key_press_temporary_analysis_buffer[6] = D;
receive_key_press_temporary_analysis_buffer[7] = E;
receive_key_press_temporary_analysis_buffer[8] = 3;
receive_key_press_temporary_analysis_buffer[9] = 4;
Below essentially is how I use both arrays in strstr():
char* is_eui_only_content_in_receive_key_press_analysis = strstr(receive_key_press_temporary_analysis_buffer, EUI_only);
printf("\n\rResult of is_eui_only_content_in_receive_key_press_analysis: %s\n\r", is_eui_only_content_in_receive_key_press_analysis);
Basically when I print the outcome of strstr() it gives me:
Result of is_eui_only_content_in_receive_key_press_analysis: CDE34
On the other hand if I reinitialise my EUI_only follows:
EUI_only[] = "ABCDE";
Essentially I get the expected result from the strstr() i.e.
Result of is_eui_only_content_in_receive_key_press_analysis: ABCDE34
Why could it be the strstr() doesn't give me my expected result when I utilise my dynamically populated EUI_only[] array?
Thanks, Alex.