title: Ask to input number and store in array BUT checking if it already exists
body: <p>I am writing a function for a program that asks the user to input a "student id number" and stores it in the array. Before storing the function has to check if we don't already have that number in the array because the student numbers must be unique. It also includes a pointer to an int that represents how many student numbers have been stored so far.
  I have written some code but it is not working :( would anyone please shed some light?
  This is my code:</p>
  
  <pre><code>void update_student_id(int a[], int*pnum)
  {
          int temp,h;
          for (h=0;h&lt;=*pnum;h++){
                  printf("&gt;&gt;&gt;Student ID:");
                  scanf("%d",&amp;temp);
                          if (temp==a[h]){
                                  printf("ERROR:%d has already been used!\n",temp);
                                  h=*pnum+1;
                          }
                          else
                              h=*pnum+1;
              }
          a[*pnum]=temp;
          *pnum++;
  </code></pre>
  
  <p>Ok, new version with 2 for loops, improving but not working yet :(</p>
  
  <pre><code>void update_student_id(int a[], int*pnum)
  {
      int temp,h,i;
      for (h=0;h&lt;=*pnum;h++){
              printf("&gt;&gt;&gt;Student ID:");
              scanf("%d",&amp;temp);
  
              for(i=0;i&lt;=*pnum;i++)
                      if (temp==a[i]){
                              printf("ERROR:%d has already been used!\n",temp);
                              i=*pnum+1;
                      }
                      else    i++;
              }
          a[*pnum]=temp;
          (*pnum)++;
  }
  </code></pre>
  
  <p>Problem solved with Dennis' help, final code:</p>
  
  <pre><code>void update_student_id(int a[], int*pnum)
  {
      int temp,h,i,canary;
      for (h = 0; h &lt;= *pnum; h++) {
              printf("&gt;&gt;&gt;Student ID:");
              scanf("%d", &amp;temp);
  
      canary = 0;
      for (i = 0; i &lt; *pnum; i++) {
              if (temp == a[i]) {
              printf("ERROR:%d has already been used!\n",temp);
              canary = 1;
              break;
              }
      }
      if (canary == 0) {
              a[*pnum] = temp;
              (*pnum)++;
              break;
          }
  }
  
  return;}
  </code></pre>