title: Application of Backtracking algorithm to find minimum number of semester to graduate
body: <p><img src="https://i.stack.imgur.com/WwSk1.png" alt="enter image description here">
  I'm taking input from a file , which contains </p>
  
  <ol>
  <li>No of courses and max allowed course per semester</li>
  <li>All Course name(5 alphanumeric max)</li>
  <li>couse name,Offered sem, number of prereqs, Prereq courses.</li>
  <li>-1 and -1 at the end
  The output will be the minimum number of semester to complete all courses.</li>
  </ol>
  
  <p>This is my code, so that you know I've done work. My code is compiling and executing, but not showing the number of sems to complete courses.
  Please tell me where I'm doing wrong</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;stdbool.h&gt;
  #include&lt;string.h&gt;
  #include&lt;ctype.h&gt;
  
  char garbage[12][6];
  char courseIdentifier[12][6],prereqIdentifier[12][5][6];
  char semOffered[12];
  bool done[12];
  
  bool allDone(int);
  bool donePrereq(int,int);
  
  int main(void)
  {
      FILE *fp;
      fp = fopen("graduate.in","r");
      int n,m,p;
      int i,j,k;
      for(i=0;i&lt;12;i++)
      {
          strcpy(courseIdentifier[i],"");
      }
      for(i=0;i&lt;12;i++)
      {
          for(j=0;j&lt;5;j++)
          {
              strcpy(prereqIdentifier[i][j],"");
          }
      }
      fscanf(fp,"%d %d",&amp;n,&amp;m);// take n,m
      while(n != -1)
      {
  
          if( !(1&lt;=n &amp;&amp; n&lt;=12) || !(2&lt;=m &amp;&amp; m&lt;=6) )
          {
              printf("Wrong input");
          }
          for(i=0;i&lt;n;i++) //the list of offered courses
          {
              fscanf(fp,"%s",garbage[i]);
          }
          for(i=0;i&lt;n;i++)
          {
              fscanf(fp,"%s %c %d",courseIdentifier[i],&amp;semOffered,&amp;p);//the name of course, sem,no. of prereqs
              for(j=0;j&lt;p;j++)
              {
                  fscanf(fp,"%s",prereqIdentifier[i][j]);
              }
          }
  
          int sem=1;
          char semNow = 'F';
          for(i=0;i&lt;n;i++)
          {
              done[i]=false;
          }
          while(!allDone(n))
          {
              int count=0;
              //while(count&lt;=m)
              //{
                  for(i=0;i&lt;n;i++)
                  {
                      if( (semOffered[i]==semNow || semOffered[i]=='B') &amp;&amp; donePrereq(p,n))
                      {
                          done[i] = true;
                          count++;
                      }
                  }
  
              //}
              sem++;
              if(semNow=='F')
              {
                  semNow='S';
              }
              else if(semNow=='S')
              {
                  semNow='F';
              }
          }
          printf("minimum number of semesters = %d\n",sem);
          fscanf(fp,"%d %d",&amp;n,&amp;m);// take n,m
      }
      return 1;
  }
  
  bool allDone(int n)
  {
      bool returnBool=true;
      int i;
      for(i=0;i&lt;n;i++)
      {
          returnBool = returnBool &amp;&amp; done[i];
      }
      return returnBool;
  
  }
  
  bool donePrereq(int p,int n)
  {
      bool returnBool=true;
      int i,j;
      for(i=0;i&lt;p;i++)
      {
          for(j=0;j&lt;n;j++)
          {
              if(strcmp(prereqIdentifier[i][j],courseIdentifier[j]) ==0 )
              {
                  printf("prereq matched\n");
                  returnBool = (returnBool&amp;&amp;done[j]);
              }
          }
      }
      return returnBool;
  }
  </code></pre>