简体   繁体   中英

Unable to assign values to an array

Look at this piece of code.. In this I am taking input from a file and assigning to an array sudoku[][] .. and simultaneously assigning those values to TempArr[][] (another array)..

But when I checked the values of TempArr[][] after assigning, there aren't same as in sudoku[][].

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
        }
    }
}

So, when I replaced "sudoku[][]" with "TempArr[][]", its working.. ie, if(fscanf(ip_file,"%d",&TempArr[i][j])==1)

Why this is happening and how do I handle this situation ?

TempArr[i][j]==sudoku[i][j];

See the == ? That wouldn't be assigning ;)

Edit: Also worth noting - the compiler can help you with these things. If you use the -Wall option when compiling, it will tell you:

> gcc -Wall -o test test.c
test.c:13:9: warning: statement with no effect [-Wunused-value]

There's a number of helpful warning levels you can specify to alert you of these things:

http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

嗯, ==不是赋值,它是对相等性的检验。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM