LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 11-18-2009, 03:42 AM   #1
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 210

Rep: Reputation: 32
Get value for variable name defined as string


Hello,

I would like to known if it possibe to obtain a value of variable defined as string.

For example:

char* varname[] = {"test", "dog"}
test = 5;
dog = 8;

Can I obtain value of varname[1]???

I use C++.

Best regards.
 
Old 11-18-2009, 03:55 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
homework eh?
at least try something.
 
Old 11-18-2009, 05:04 AM   #3
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 210

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by bigearsbilly View Post
homework eh?
at least try something.
Hello,

I am sorry, but I dont understand what are you tried to say.
Homework??? at least, ten years or more last time when I have opened a book to study.

I have try some code, but it is to insert all variables in a list.

Code:
#include <iostream>
#include <map>
#include <utility> // make_pair
using namespace std;
 
int main()
{
        typedef map<char, int> mapType;
	mapType myMap;
 
	// insert elements using insert function
	myMap.insert(pair<char, int>('a', 1));
	myMap.insert(pair<char, int>('b', 2));
	myMap.insert(pair<char, int>('c', 3));
	myMap.insert(mapType::value_type('d', 4)); // all standard containers provide this typedef
	myMap.insert(make_pair('e', 5));           // can also use the utility function make_pair
 
        // erase the first element using the erase function
	mapType::iterator iter = myMap.begin();
        myMap.erase(iter);
 
        // output the size of the map
        cout << "Size of myMap: " << myMap.size() << '\n';
 
	cout << "Enter a key to search for: ";
	char c;
	cin >> c;
 
	// find will return an iterator to the matching element if it is found
	// or to the end of the map if the key is not found
	iter = myMap.find(c);
	if( iter != myMap.end() ) 
		cout << "Value is: " << iter->second << '\n';
	else
		cout << "Key is not in myMap" << '\n';
 
        // clear the entries in the map
        myMap.clear();
}
but it is very hard to handle several variables.
Then, I have look for information about it, and I dont find clear information (tcl_getvar of tcl library, but I dont know if I can use it)

And now, I am here, to look for help, but I see that it is very hard to find it.

And know in my language, No se por que te pones asi o por que me saltas con eso de que si son "homework". Me parece que la respuesta esta fuera de contexto y no tengo ganas de discutir con nadie.

Best regards
 
Old 11-18-2009, 05:20 AM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
since its not homework, then tell us what you are trying to do? A low level system programming project?? driver programming?? game programming?? If they are not one of these, then i suggest learning and using a scripting language instead. they have easier to use data structures and much more.
 
Old 11-18-2009, 05:30 AM   #5
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 210

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by ghostdog74 View Post
since its not homework, then tell us what you are trying to do? A low level system programming project?? driver programming?? game programming?? If they are not one of these, then i suggest learning and using a scripting language instead. they have easier to use data structures and much more.
Ok!!

Well, I have develop program, Qt with Rt threads that controlled a machine.
It works fine.
Now I am interesting to read some variables in a webserver.
My idea is use mysql server and connect webpage to mysql table where is a name of var and value. Webpage and mysql works.

But now I have problem. I have a file where is the name of variables that I would like to read value a insert in mysql table, and I dont know how to eval value for variable name defined as string.

Code:
sprintf(sql_consulta, "UPDATE watch set value = '%ld' WHERE name='contador1'", counter.general);
mysql_query(conn, sql_consulta);
For example, counter.general is a var of program, and in file there is a line with this string "counter.general".

More or less, this is I trying to do.

Best regards.

Last edited by webquinty; 11-18-2009 at 05:43 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined xpucto Linux - Newbie 7 06-21-2010 05:30 AM
Help: removing a variable substring from a string variable in sh script gnparsons Programming 2 06-04-2008 05:21 PM
c++: can you set a string to a #defined value? BrianK Programming 8 02-29-2008 03:25 PM
Neither JAVA_HOME nor the JRE_HOME variable defined Raakh Linux - Newbie 9 06-02-2007 06:40 AM
Replace variable with user defined variable ce124 Programming 10 04-13-2007 09:29 AM


All times are GMT -5. The time now is 07:13 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration