473,403 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

the value of variable changes after the end of for loop

56
Expand|Select|Wrap|Line Numbers
  1.     for (int raw1=0;raw1<4;raw1++){
  2.  
  3.         for (int column2=0;column2<4;column2++){
  4.             unsigned char temp=0x00;
  5.  
  6.             for (column1=0;column1<4;column1++){
  7.                 int z1=7;
  8.                 int p1[8]={00000000};
  9.  
  10.                 unsigned char temp2;
  11.  
  12.                 u1 = output_substitute_byte1[column1][column2];
  13.  
  14.                 while( u1!=0){
  15.                 p1[z1]=u1%2;
  16.                  u1 = u1/2;
  17.                 z1--;
  18.                 }
  19.  
  20.     unsigned char k= output_substitute_byte1[column1][column2];
  21.  
  22.     if(mix_matrix[raw1][column1]==0x01){temp=temp^output_substitute_byte1[column1][column2];}
  23.  
  24.     else if(mix_matrix[raw1][column1]==0x02&&p1[0]==0)
  25.     {
  26.         temp2=output_substitute_byte1[column1][column2]<<1;
  27.  
  28.         temp=temp^temp2;
  29.     }
  30.  
  31.     else if(mix_matrix[raw1][column1]==0x02&&p1[0]==1)
  32.     {
  33.         temp2=(output_substitute_byte1[column1][column2])<<1;
  34.         temp2=temp2 ^ 0x1B;
  35.         temp=temp^temp2;
  36.     }
  37.  
  38.     else if(mix_matrix[raw1][column1]==0x03&&p1[0]==1)
  39.     {    
  40.         unsigned char temp3;
  41.         temp3=output_substitute_byte1[column1][column2];
  42.         temp2=output_substitute_byte1[column1][column2]<<1;
  43.         temp2=temp2^temp3;
  44.         temp2=temp2 ^0x1B;
  45.         temp=temp^temp2;
  46.     }
  47.  
  48.     else if(mix_matrix[raw1][column1]==0x03&&p1[0]==0)
  49.     {    
  50.         unsigned char temp3;
  51.         temp3=output_substitute_byte1[column1][column2];
  52.         temp2=output_substitute_byte1[column1][column2]<<1;
  53.         temp2=temp2^temp3;
  54.         temp=temp^temp2;
  55.     }
  56. }
  57.  
  58.   output_mix_column[column1][column2]=temp;
  59.   printf("%0x\t",  output_mix_column[column1][column2]);
  60.  
  61.  }
  62. }
when i print the variable output_mix_column inside the for loop as shown in the code, it prints the right output, but when i print it outside the for loop, it changes its value
i don't know where is the problem
Jan 19 '14 #1
1 1565
Luuk
1,047 Expert 1GB
In c, when you do something like:
Expand|Select|Wrap|Line Numbers
  1. for (int column2=0;column2<4;column2++){
then the variable column2 is 'local' to the block that is defined after it or, in other word, the value of it is undefined after the for-loop.
Jan 19 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: mast2as | last post by:
hi guys I wonder if there's a way of doing something like that in C++ which is more elegant then the "basic" approach. I have lets say a class TOptions1 which has a few member variables. It is...
5
by: AMP | last post by:
Hello, I have a Form level variable: public partial class Form1 : Form { byte rxHeader = 0;.............................. That gets passed from one function to another: if...
2
by: Vanecelli | last post by:
The below code is calling a function that populates a certain number of listbox es with options. IT loops as it should if there are only 2 instances of k, but anything greater and the second variable...
6
by: SDyke | last post by:
In a class I have a string variable with a value of: filePath = "file://" + "gvas400/home/sde/pdffiles/817739P1.pdf"; This works great when I run the web app on my local web host server. ...
1
bergy
by: bergy | last post by:
I have a user control class, when a user selects the control (or it's children) the background of the control turns blue. When the user exits, it returns to its "unselected" state. I have...
16
by: littlegreen | last post by:
Hi all, I would like to know how to assign and get the form value when I using it in a loop. I cannot get all the input that I inserted in 'Desc' part and it is from this site. May I know to get...
3
by: maxin | last post by:
I have a xml file: <E1MBXYI SEGMENT="1"> ... <CHARG>1000024187</CHARG> ... </E1MBXYI> <E1MBXYI SEGMENT="1"> ... <CHARG>1000024187</CHARG>
4
by: abueno | last post by:
cout<<"Do you want to enter another score, enter 'y' or 'n' ?"; cin>>wish; cout<<endl; while((wish =='Y')||(wish =='y')) {
5
by: dave816 | last post by:
Sorry for the Excel question in an Access forum...................I don't see an Excel forum and there's probably a reason for that but figured I'd give this a shot anyway. Again sorry, delete if...
2
ditditsasa
by: ditditsasa | last post by:
while (false !== ($sfname = readdir($dh))) { if (substr($sfname, 0, 1) == '.') continue; if ($sfname == 'CVS' ) continue; $sitedir = "$OE_SITES_BASE/$sfname"; if...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.