LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-19-2013, 02:47 AM   #1
kelvincholamattathil
LQ Newbie
 
Registered: May 2012
Location: bangalore,india
Posts: 3

Rep: Reputation: Disabled
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]);
}

Last edited by kelvincholamattathil; 03-19-2013 at 05:36 AM.
 
Old 03-19-2013, 03:20 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
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?

Last edited by pan64; 03-19-2013 at 03:24 AM.
 
Old 03-19-2013, 03:39 AM   #3
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Rep: Reputation: 43
Are you using c or c++? I think c? strcpy might be useful for you.
 
Old 03-19-2013, 08:40 AM   #4
mina86
Member
 
Registered: Aug 2008
Distribution: Debian
Posts: 517

Rep: Reputation: 229Reputation: 229Reputation: 229
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" };
const char **str = arr;
size_t i;

for (i = 0; i < sizeof arr / sizeof *arr; ++i, ++str) {
    puts(*str);
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] android - how to access strings in a custom xml file in res/values? eantoranz Programming 5 11-13-2012 10:11 AM
[SOLVED] reference bash array values, using a variable with a value of the array name gusthecat Programming 5 03-07-2012 03:41 PM
[SOLVED] Array of words(strings)- please help! stefanolima Programming 4 07-12-2010 04:15 AM
[bash] indirect array reference to array with values containing spaces Meson Linux - Software 9 06-04-2010 09:38 PM
Array and check strings mech123 Linux - Newbie 6 05-03-2010 07:48 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration