title: How to get string as return value from function in C?
body: <p>I am a newbie in C and am trying to make a hangman game where a player will have to guess a random word selected by the program. But I am stuck in getting the word. I tried a lot and found some answers on SO but could not relate it to my case.</p>
  <p>Here's the code:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  
  char dictionary[3][15] = {&quot;food&quot;,&quot;cat&quot;,&quot;coder&quot;};
  //15 is max length of each word
  
  char getWord() {
      srand(time(0));
      char *random_elem = dictionary[rand()%3];
      printf(random_elem);
      return random_elem;
  }
  
  
  void gamePlay() {
      *word = getWord();
      printf(*word);
      return;
  }
  
  int main() {
  
      printf(&quot;Welcome to Hangman\n&quot;);
      printf(&quot;------------------------------------\n\n&quot;);
  
      gamePlay();
  }
  </code></pre>
  <p>The <code>printf</code> in the <code>getWord()</code> works but not in <code>gamePlay()</code></p>
  <p>The following error is generated:</p>
  <pre><code>&lt;stdin&gt;:11:12: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
      printf(random_elem);
             ^~~~~~~~~~~
  &lt;stdin&gt;:11:12: note: treat the string as an argument to avoid this
      printf(random_elem);
             ^
             &quot;%s&quot;, 
  &lt;stdin&gt;:12:12: error: cannot initialize return object of type 'char' with an lvalue of type 'char *'
      return random_elem;
             ^~~~~~~~~~~
  &lt;stdin&gt;:17:6: error: use of undeclared identifier 'word'; did you mean 'for'?
      *word = getWord();
       ^~~~
       for
  &lt;stdin&gt;:17:6: error: expected expression
  &lt;stdin&gt;:18:13: error: use of undeclared identifier 'word'
      printf(*word);
              ^
  1 warning and 4 errors generated.
  </code></pre>
  <p>OS: Android 11
  App: Cxxdroid</p>
  <p><em>If that might help</em></p>