Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8045795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:38:40+00:00 2026-06-05T05:38:40+00:00

Very new to C so please bear with me. I have a function that

  • 0

Very new to C so please bear with me. I have a function that takes in 3 char * variables, opcode, arg1 and arg2.

arg1 and arg2 can either be (1) a string containing the name of a variable holding an unsigned int, or (2) an actual integer.

Either way, I need to get the actual integer out. I am trying to use atoi so far but it seems to be returning 0 for the first case.

i.e.

sscanf(instruction, "%s %s %s", opcode, arg1, arg2);

sum = atoi(arg1) + atoi(arg2);

I can’t post the entire code as it doesn’t belong to me, but hopefully the above demonstration helps a little?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:38:42+00:00Added an answer on June 5, 2026 at 5:38 am

    As I said in my comment, you can’t expect to retrieve the value of a named variable at run-time, in C. Variable names are not something that is kept when the code runs, then it’s pure machine code and all variables have been “cooked down” to memory addresses. The names are no longer around.

    The atoi() function converts a string holding an integer, such as "4711", into the actual value, 4711. That’s all it does, it cannot retreive values “by name” in any way.

    If you want to have a mechanism to map variable names to values when the program runs, you are going to have to create that mechanism yourself, since the language does not have one. For instance, you could create some kind of array of structures that let you associate names with values, but that would of course require you to initialize that array.

    Something like this:

    int foo = 12;
    char *vname = "foo";
    
    print("the value of %s is %d\n", vname, get_variable_value(vname));
    

    simply is not going to happen in C, the function get_variable_value() cannot exist.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am VERY new to mySQL, please bear with me. I have an array
I'm very new to WPF, so please bear with me. Basically I have defined
I am very new to Perl, so please bear with my simple question: Here
I'm very, very new to PHP, so please bear with me. I'd like to
I am very new to using preg_replace and such so please bear with me.
I'm very new to iPhone development so please bear with me. I'm following the
I'm very new to working with lift, so please bear with me. If I
I'm coming from C# and very new at this so please bear with me.
I'm very new to Ruby, so please bear with me. Why is it a
I am very very new to OpenGL, so please bear with me. :) I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.