baffling printf error in c++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abhdkjsd
    New Member
    • May 2012
    • 1

    baffling printf error in c++

    Hello to all,
    I have a baffling problem with printf in Borland c++ v5.2 as follows:
    If I use the command:
    Printf(“ ”);
    Before the condition :
    If(b[loc[pn][0]][0] == loc[pn][0]){
    ….
    }
    My code works correctly, but if I delete it this error occurs:
    “Threat stopped access violation at 0x403492 read of address … “
    Have every one experienced a similar problem or could help me?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    I don't the problem is due to printf.

    I think it's because loc[pn][0]][0] == loc[pn] is being used as an array index. Array indexes must be integers. The result of operator== is true or false. While these may display as 1 and 0, it doesn't mean the values are integers.

    Do something like:

    Code:
    if (loc[pn][0]][0] == loc[pn])
    {
       use b[1] etc...
    }
    else
    {
       use b[0] etc...
    }
    I think you are in the land of indeterminate results and that printf is misleading you.

    Comment

    Working...