using variable names

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bimbam
    New Member
    • Aug 2007
    • 19

    using variable names

    Hi,

    Does anyone of you knows how to make a string to be interperted as a variable name in C? For example, is there a function so that the following lines print out "test"?

    Code:
    char variable[10];
    strcpy(function("variable"), "test");
    printf("%s\n",variable );
    It would simplify a lot of things to me...

    Cheers
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    "test" with quptation marks??

    If so, just mae the quotation marks part of the string:
    [code=c]
    strcpy(function ("variable") , "\"test\"") ;
    [/code]

    Comment

    • bimbam
      New Member
      • Aug 2007
      • 19

      #3
      Originally posted by weaknessforcats
      "test" with quptation marks??

      If so, just mae the quotation marks part of the string:
      [code=c]
      strcpy(function ("variable") , "\"test\"") ;
      [/code]
      Sorry, that's not what I meant. My question was about the function called "function" in my example that would have as input argument a string and would output the variable of which the name is contained in the string. I realise my explanation is not so clear but it should be easier to understand reading the example at the same time.

      Cheers

      Comment

      • oler1s
        Recognized Expert Contributor
        • Aug 2007
        • 671

        #4
        Symbol names, like variable names and function names, exist for the convenience of the programmer. That is to say, the variable names themselves do not exist at runtime. Therefore, you cannot instruct the compiler at runtime to find a variable with a certain name.

        So the short answer is, you cannot achieve what you want.

        Comment

        Working...