newbie question on evaluating a string variable 
Author Message
 newbie question on evaluating a string variable

Hello.  I have what I think is a simple newbie question, but I have had no
luck in finding an answer on the web or in books.  I have a structure that
contains a string.  Call it Struct[i].string.  I also have a (gsl) function
that requires the string value that is contained in the structure.  How do I
convert the variable Struct[1].string to its literal value?  For example, if
"Bob" is the value stored in Struct[1].string, how do I convert the variable
name Struct[1].string to "Bob"?  C does not seem to have an Evaluate
function to change a variable name to the value it contains.

Thanks,
John

--



Thu, 02 Feb 2006 12:44:47 GMT  
 newbie question on evaluating a string variable

Quote:

> Hello.  I have what I think is a simple newbie question, but I have had no
> luck in finding an answer on the web or in books.  I have a structure that
> contains a string.  Call it Struct[i].string.  I also have a (gsl) function
> that requires the string value that is contained in the structure.  How do I
> convert the variable Struct[1].string to its literal value?  For example, if
> "Bob" is the value stored in Struct[1].string, how do I convert the variable
> name Struct[1].string to "Bob"?  C does not seem to have an Evaluate
> function to change a variable name to the value it contains.

The question indicates some confusion about several matters.
C has no string type, but rather uses array of type char
with the convention that after the last valid character is
a 0-valued char.  (There is also a "wide character" type,
capable of repreenting a wider variety of characters, but
evidently you're not dealing with that yet.)  In C source
code, "...", which is called a "string literal", is used
for two primary purposes: to provide initial character
values to initialize a declared (named) char array, and as
an "anonymous" object (also a char array) having the same
contents.  The 0-valued terminating char is considered part
of the string literal.

The content of a variable constitutes its value; you don't
need to "change" anything for that to happen.  Just use the
value of the variable appropriately.  Note that in C, the
declared name of an array when used in an expression will
in most cases be automatically converted to a pointer to
the first element of the array.  The standard library
functions that deal with "strings" are designed with that
in mind.
--



Fri, 03 Feb 2006 05:54:47 GMT  
 newbie question on evaluating a string variable


writes
Quote:
>Hello.  I have what I think is a simple newbie question, but I have had no
>luck in finding an answer on the web or in books.  I have a structure that
>contains a string.  Call it Struct[i].string.  I also have a (gsl) function
>that requires the string value that is contained in the structure.  How do I
>convert the variable Struct[1].string to its literal value?  For example, if
>"Bob" is the value stored in Struct[1].string, how do I convert the variable
>name Struct[1].string to "Bob"?  C does not seem to have an Evaluate
>function to change a variable name to the value it contains.

You just pass it to a function which expects a string. e.g.
puts(Struct[i].string)
--
Walter Briscoe
--



Fri, 03 Feb 2006 05:55:01 GMT  
 newbie question on evaluating a string variable

Quote:

> "Bob" is the value stored in Struct[1].string, how do I convert the variable
> name Struct[1].string to "Bob"?  

You don't convert at all --- there's nothing to do.  Just use
Struct[1].string as an expression in the place where you need a
string-valued input.

Quote:
> C does not seem to have an Evaluate function to change a variable
> name to the value it contains.

You apparently haven't grasped the difference between a compiled and
an interpreted language yet.  In C, the distinction you're talking
about, between the name and value of a variable, essentially doesn't
exist.  About the only exception from this rule is the sizeof()
operator.
--

Even if all the snow were burnt, ashes would remain.
--



Fri, 03 Feb 2006 05:55:15 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Evaluate a string as a variable

2. Newbie question: Strings and string manipulation.

3. Evaluating Variables during Runtime?

4. Evaluating Variables during Runtime

5. Evaluate variable

6. Evaluating functions using IDebugger Evaluate member.

7. Newbie Variable question

8. Newbie C question regarding static & const variables

9. evaluating strings in C#

10. evaluating strings??

11. Turning a string into a function and evaluate it

12. Global variables (newbie question)

 

 
Powered by phpBB® Forum Software