Thread: Not understanding where this value is coming from... Help?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2016
    Posts
    3

    Post Not understanding where this value is coming from... Help?

    Code:
    int main(){
         int *map[12][12][5], monster = 0, mnstMdfy = 0,mnstDths[26];
    
         mnstDths[6] = 0;     
    
         map[1][0][0] = (int *)malloc(sizeof(int));
    
         map[1][0][0] = 71;
    
         printf("\nMap = %d\n",map[1][0][0]);
    
         monster = map[1][0][0] - 65;
         printf("\nMonster = %d\n",monster);
         mnstMdfy = mnstDths[monster] * 5;
         printf("\nModifier = %d\n",mnstMdfy);
    }
    This is a rough outline of the actual code, but the given code should be sufficient. After running the program, the print statements have given me results such as...

    "Map = 71

    Monster = -189

    Modifier = 335"

    I've looked over this many times and cant seem to identify where the values of Monster and Modifier come from. They should be zero, but obviously that's not the case. Any help is appreciated!

    EDIT: I have found that splitting the monster assignment into...
    monster = map[1][0][0];
    monster = monster - 65;
    ... fixes this problem, however I still am not sure as to why this occurs. (Maybe the 65 is changing the address?) Please let me know!
    Last edited by Caleb Duncan; 08-05-2016 at 02:52 AM. Reason: Found a fix

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help coming up with an answer
    By burnsidex in forum C Programming
    Replies: 2
    Last Post: 09-02-2013, 09:38 PM
  2. my second coming
    By thestien in forum Game Programming
    Replies: 6
    Last Post: 12-17-2007, 09:54 AM
  3. what's the world coming to?
    By Waldo2k2 in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 11-22-2002, 12:00 PM
  4. What is the world coming to?
    By Eibro in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 09-04-2002, 01:57 PM

Tags for this Thread