Unable to assign to a variable

This is a discussion on Unable to assign to a variable within the C Programming forums, part of the General Programming Boards category; Code: for (i=0;i<size;i++) { for (j=0;j<size;j++) { if(fscanf(ip_file,"%d",&sudoku[i][j])==1) { //copy to TempArr TempArr[i][j]==sudoku[i][j]; } else { perror ("fscanf failed on ...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    113

    Question Unable to assign to a variable

    Code:
    for (i=0;i<size;i++)
        {
            for (j=0;j<size;j++)
            {
                if(fscanf(ip_file,"%d",&sudoku[i][j])==1)
                {         
                          //copy to TempArr
                          TempArr[i][j]==sudoku[i][j];
                }
                else
                {
                    perror ("fscanf failed on input file.\n");
                    // return error
                }
            }
        }
    Here I'd like to copy sudoku[][] to TempArr[][] but when I checked the values of TempArr[][], they are completely different. Why this is happening.

    When I removed
    Code:
    if(fscanf(ip_file,"%d",&sudoku[i][j])==1)
    , and replaced with TempArr[][], its working.

    Why this is happening and how to handle this situation.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,801
    You accidentally used comparison operator == when you wanted to use copy assignment operator =.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    113

    Solved!

    Yeah, got it. I wasn't looking at it. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to assign text to its own variable
    By stephen101 in forum C Programming
    Replies: 18
    Last Post: 12-13-2010, 06:37 PM
  2. Is it possible to assign a type to a variable?
    By Kennedy in forum C Programming
    Replies: 20
    Last Post: 06-10-2010, 04:46 PM
  3. Assign this to a variable
    By ABuNeNe in forum C Programming
    Replies: 5
    Last Post: 11-25-2009, 09:21 PM
  4. how to assign a map iterator to an int variable?
    By Masterx in forum C++ Programming
    Replies: 22
    Last Post: 05-02-2009, 09:05 AM
  5. Assign string to variable?
    By 98dodgeneondohc in forum C Programming
    Replies: 8
    Last Post: 04-24-2005, 01:51 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21