how to access the values from readonly array of strings
I need to access newPrompt1 values .But its showing NULL ,is there any way to get the values
#include<stdio.h> #include<string.h> int main() { unsigned char *newPrompt="# "; unsigned char **newPrompt1 =NULL; unsigned char au1CLIPromptStrings [7][30] = { "", "Login: ", "Password: ", " 0123456789012345678901234", " 0123456789012345678901234", }; newPrompt1 = au1CLIPromptStrings; // here am assigning the address printf("b1 = %u and b2 = %u\n",newPrompt1,au1CLIPromptStrings); printf("a1 = %s and a2 = %s\n",newPrompt1[3],newPrompt1[4]); } |
it is set to NULL, so it must show null. Am I missed something?
sorry, in your code you have 2 { and 3 }, so it is not ok. What have you really made? |
Are you using c or c++? I think c? strcpy might be useful for you.
|
au1CLIPromptStrings is a two dimensional array so it's not compatible with unsigned char **. What you need is to define it as an array of pointers to const char. Also note, that you should not use unsigned char in this context.
Code:
const char *arr[] = { "foo", "bar", "baz" }; |
All times are GMT -5. The time now is 03:52 AM. |