title: Why is char* foo() returning empty string?
body: <p>I'm writing a C code that checks the number of occurrences of a word (entered by the user) in a text file, prints the count per line, and the total count on the screen, and compares the word with the last word of the file.</p>
  
  <p>I have dedicated a function to fetch the last word called "Fetch", that fetches the word and returns it to the main function. then another function counts the occurrences, then a third function that actually compares the two strings using strcmp().</p>
  
  <p>my problem is that the function char* Fetch() is seemingly returning empty strings for some reason. Note that I wanted to check where the problem actually is, so I tried to print the result inside the function on the screen instead of returning it to main() and it worked!!, so seemingly, the problem is the return statement, What could be the problem??  </p>
  
  <p>char* Fetch() called in main(): </p>
  
  <pre><code>//step 3: fetch the last word in the file
  Lword = Fetch();
  printf("the last word is %s", Lword);
  </code></pre>
  
  <p>char* Fetch():</p>
  
  <pre><code>char* Fetch()
  {
      char text[1000];
      fread(text, sizeof(char), sizeof(text), spIn);
      for(int i = 0; i &lt; strlen(text); i++)
      {
          if(isspace(text[strlen(text) -1 -i])) //if space
          {
              return (text + (strlen(text)-i));  //return a pointer to the element after the space
          }
      }
  
  
  }
  </code></pre>
  
  <p>declarations in main:</p>
  
  <pre><code>char Uword[20], *Lword;
  int TotalCount;
  </code></pre>