title: How to fix error: incompatible types when returning type 'struct {aka struct <anonymous>}
body: <p>I'm making a code that returns a struct with random values. I keep getting error: incompatible types when returning type 'student {aka struct }' but 'struct student *' was expected return s;</p>
  
  <p>I've tried many things and have looked all over the internet, but i couldn't find a solution.</p>
  
  <p>Any help would be Appreciated.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  
  int method = 3; //if 0, organize by all. if 1, organize by grade. if 3, organize by speed.
  
  
  char first[40];
  char last[25];
  
  char* genName();
  
  struct student* genStudent();
  
  typedef struct
  {
      char name[60];
      int score;
      double time;
  } student;
  
  char firstNames[][15] =
  {
  {"John"},
  {"Jim"},
  {"Tim"},
  {"Sam"},
  {"Jack"},
  {"Larry"},
  {"Bob"},
  {"Mack"},
  {"Kyle"},
  {"Tom"},
  {"Joe"},
  {"Dan"}
  };
  
  char lastNames[][25] =
  {
  {" Howards"},
  {" Nyles"},
  {" Jones"},
  {" White"},
  {" Myles"},
  {" Simones"},
  {" Smith"},
  {" Johnson"},
  {" Williams"},
  {" Brown"},
  {" Jackson"},
  {" Martin"},
  {" Davis"},
  {" Thompson"},
  {" Moore"},
  {" Wick"},
  };
  
  int compare(const void*, const void*);
  
  student s1 = {"Jim Howards", 89, 4.90};
  student s2 = {"Tim Nyles", 76, 6.12};
  student s3 = {"John Jones", 97, 7.56};
  student s4 = {"Sam White", 50, 1.12};
  student s5 = {"Jack Myles", 88, 3.90};
  
  int main()
  {
  
         student array[] = {s1, s2, s3, s4, s5};
  
  
  qsort(array, (sizeof(array)/sizeof(array[0])), sizeof(array[0]), compare);
  
  if (method == 1)
  {
      for (int i = 0; i &lt; (sizeof(array)/sizeof(array[0])); i++)
      {
          printf("%d.%s, with a score of %d%%\n", i+1, array[i].name, array[i].score);
      }    
  }
  else
  {
      if (method == 2)
      {
          for (int i = 0; i &lt; (sizeof(array)/sizeof(array[0])); i++)
          {
          printf("%d.%s, with a time of %1.2f minutes\n", i+1, array[i].name, array[i].time);
          }    
      }
      else
      {
          if (method == 3)
          {
              for (int i = 0; i &lt; (sizeof(array)/sizeof(array[0])); i++)
              {
                  printf("%d.%s, with a score of %d%%, and a time of %1.2f\n", i+1, array[i].name, array[i].score, array[i].time);
              }
          }
      }
  }
  
  
  
  char* hi = genName();
  printf("%s", hi);
  
  return 0;
  }
  
  int compare(const void * num1, const void * num2)
  {
      student *st1 = (student *)num1;
      student *st2 = (student *)num2;
  if (method == 1)
  {
      if (st1-&gt;score &lt; st2-&gt;score)
      {
          return 1;
      }
      if (st1-&gt;score == st2-&gt;score)
      {
          return 0;
      }
      if (st1-&gt;score &gt; st2-&gt;score)
      {
          return -1;
      }
  }
  else
  {
      if (method == 2)
      {
          if (st1-&gt;time &gt; st2-&gt;time)
          {
              return 1;
          }
          if (st1-&gt;time == st2-&gt;time)
          {
              return 0;
          }
          if (st1-&gt;time &lt; st2-&gt;time)
          {
              return -1;
          }   
      } 
      else
  {
      if (method == 3)
      {
  
          if (st1-&gt;score &lt; st2-&gt;score)
          {
              return 1;
          }
  
          if (st1-&gt;score == st2-&gt;score)
          {
             if (st1-&gt;time &gt; st2-&gt;time)
              {
                  return 1;
              }
              if (st1-&gt;time == st2-&gt;time)
              {
                  return 0;
              }
              if (st1-&gt;time &lt; st2-&gt;time)
              {
                  return -1;
              }  
          }
          if (st1-&gt;score &gt; st2-&gt;score)
          {
              return -1;
          }   
      } 
  }
  }
  }
  
  char* genName()
  {
      srand(time(0));
      int r = rand() % (sizeof(firstNames)/sizeof(firstNames[0]));
      strcpy(first, firstNames[r]);
      int v = rand() % (sizeof(lastNames)/sizeof(lastNames[0]));
      srand(time(0));
      strcpy(last, lastNames[v]);
      strcat(first, last);
      return first;
  }
  
  struct student* genStudent()
  {
      student s;
      srand(time(0));
      int sScore = rand() % 101;
      srand(time(0));
      double sTime = (double)rand()/(10);
      char* sName = genName();
      strcpy(s.name, sName);
      s.score = sScore;
      s.time = sTime;
      return s;
  }
  </code></pre>