title: reset variable in for loop of c code
body: <p>I am trying to write some C code to increment a ip address. I want one of the variables "j" to reset back to 0 after it reaches 256 since there are only 255 ip address per octet. My problem is I can't seem to get "j" set back to 0. Any ideas what I am doing wrong ?</p>
  
  <pre><code>int main()
  {
  
      int breakCount = 300;
  
      int j = 0;
      int x = 0;
  
      for(int i = 0; i &lt; breakCount; i++) 
      {
          printf("class-map type traffic match-all cm%d\n",i);
          printf("match source-address ipv4 100.%d.%d.0\n",x,j);
  
          j++;
  
          if (j == 256)
          {
              x++;
  
              int j = 0;
          }
      }
  
      return 0;
  }
  </code></pre>
  
  <p>/* code snip output */</p>
  
  <pre><code>match source-address ipv4 100.0.253.0
  class-map type traffic match-all cm254
  match source-address ipv4 100.0.254.0
  
  class-map type traffic match-all cm255
  match source-address ipv4 100.0.255.0
  
  class-map type traffic match-all cm256
  match source-address ipv4 100.1.256.0
  
  class-map type traffic match-all cm257
  match source-address ipv4 100.1.257.0
  </code></pre>