title: exc_bad_access in C program
body: <p>Okay, I know there is another question about "exc_bad_access" here, but that seems to deal with Objective-C and iPhone dev., while mine is only regular C.  I am new to C and am almost done with my first program until this error showed up.  I have been trying to figure it out for a couple of days and am going insane.  Any help is appreciated.
  buggy function:</p>
  
  <pre><code>void edit (int i){
      char* z;
      char* y;
      char compare1[] = "on bobbin\b\b\b\b";
      char compare2[] = "not on bobbin";
      char compare3[] = "have\b\b\b\b\b\b";
      char compare4[] = "don't have";
      char wrapedit[] = "wrapped";
      char haveedit[] = "have";
      char editing[9];
  
      FILE *wrappedlist = fopen("../../wrapped", "r+");
      FILE *havelist = fopen("../../havelist", "r+");
  
      fseek(wrappedlist, i*14, SEEK_SET);
      fseek(havelist, i*11, SEEK_SET);
  
      printf("Edit? (y=yes, n=no)");
      fgets(z, 2, stdin);
  
      if ((*z=='y') &amp;&amp; (strncmp(haveslist[i], compare4, (size_t)1) == 0)) {
          printf("Switch \"don't have\" to \"have\"? (y=yes, n=no)");
          fgets(y, 2, stdin);
  
          if (*y=='y') {
              fputs(compare3, havelist);
              fclose(wrappedlist);
              fclose(havelist);
              return;
          }
          else if(*y=='n'){
              fclose(wrappedlist);
              fclose(havelist);
              return;
          }
          printf("Invalid input.");
          return;
      }
  
      else if ((*z=='y') &amp;&amp; (strncmp(haveslist[i], compare3, (size_t)1) == 0)) {
          fpurge(stdout);
          printf("Edit \"wrapped\" or \"have\"?");
          fpurge(stdin);
          fgets(editing, 9, stdin);
  
          len = strlen(editing);
          editing[len-1]='\0';
  
          if (strcmp(editing, wrapedit)==0) {
  
          if (strncmp(wrapped[i], compare1, (size_t)1)==0) {
  
              printf("Switch \"on bobbin\" to \"not on bobbin\"? (y=yes, n=no)");
              fgets(y, 2, stdin);
              if (*y=='y') {
  
                  fputs(compare2, wrappedlist);
                  fclose(wrappedlist);
                  fclose(havelist);
                  return;
              }
              else if(*y=='n'){
                  fclose(wrappedlist);
                  fclose(havelist);
                  return;
              }
          }
              else if(strncmp(wrapped[i], compare2, (size_t)1)==0){
  
                  fpurge(stdout);
                  printf("Switch \"not on bobbin\" to \"on bobbin\"? (y=yes, n=no)");
                  fgets(y, 2, stdin);
                  if (*y=='y') {
  
                      fwrite(compare1, (size_t)strlen(compare1), 1, wrappedlist);
                      fclose(wrappedlist);
                      fclose(havelist);
                      return;
                  }
                  else if(*y=='n'){
                      fclose(wrappedlist);
                      fclose(havelist);
                      return;
          }
                  fpurge(stdout);
                  printf("Invalid input.");
          }
              fpurge(stdout);
              printf("You don't want to edit wrapped apparently.");
              fclose(wrappedlist);
              fclose(havelist);
              return;
          }
          else if(strcmp(editing, haveedit)==0){
  
              if (strncmp(haveslist[i], compare3, 1) == 0){
  
                  printf("Switch \"have\" to \"don't have\"? (y=yes, n=no)");
                  fgets(y, 2, stdin);
                  if (*y=='y') {
                      fputs(compare4, havelist);
                      fclose(wrappedlist);
                      fclose(havelist);
                      return;
                  }
                  else if(*y=='n'){
                      fclose(wrappedlist);
                      fclose(havelist);
                      return;
                  }
                  printf("Invalid input.");
              }
              else if(strncmp(haveslist[i], compare4, 1)==0){
  
                  printf("Switch \"don't have\" to \"have\"? (y=yes, n=no)");
                  fgets(y, 2, stdin);
                  if (*y=='y') {
                      fputs(compare3, havelist);
                      fclose(wrappedlist);
                      fclose(havelist);
                      return;
                  }
                  else if(*y=='n'){
                      fclose(wrappedlist);
                      fclose(havelist);
                      return;             
              }
          }
              printf("Invalid input.");
          }
              printf("Not editing.");
  
          fclose(wrappedlist);
          fclose(havelist);
  
          return;
      }
      else if(*z=='n'){
          fclose(wrappedlist);
          fclose(havelist);
          return;
      }
  
      printf("Invalid entry");
      fclose(havelist);
      fclose(wrappedlist);
      return;
  }
  </code></pre>
  
  <p>I can input a char to the fgets after the "Edit?" prompt, but then I get the exc_bad_access error.  Please help, thanks.code:</p>