title: Trying to write a C function to read in stdin to elements of a struct
body: <p>I have no idea how to call the function or what arguments to put in it. I've written the code in the main function, but I want to put it in a separate function I can call into main later. Would love some help on how I can do this!</p>
  <p>The input comes from stdin</p>
  <p>Here is the code (in the main function) that I want to put into a separate function:</p>
  <pre><code>
  
  #include &lt;stdio.h&gt; 
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;assert.h&gt;
  
  /* * * Define Constants * * */
  #define WORD_LEN 22
  #define MAX_NUM_POS_TAGS 5
  #define SIZE_POS_TAG 4
  #define MAX_NUM_VAR_FORMS 4
  #define VAR_FORM_LEN 25
  #define MAX_DICT_WORDS 100
  
  /* * * Typedefs * * */
  
  typedef char word_line_one[WORD_LEN+1];
  typedef char word_line_two[MAX_NUM_POS_TAGS+1];
  typedef char word_line_three[SIZE_POS_TAG+VAR_FORM_LEN*SIZE_POS_TAG+1];
  
  
  //getword function prototype 
  int getword(char W[], int limit);
  //check_if_valid function prototype
  int check_if_valid(char in_char);
  //stage1 function
  int stage1(char ln1[], char ln2[], char ln3[]);
  
  //main function 
  
  //stage 1 
  int main (int argc, char *argv[]) 
  {
      //define the struct for one word 
      struct
      {
          word_line_one line_one;
          word_line_two line_two;
          word_line_three line_three;
      }one_word_dict_t;
      
      //reading line 1 
      char temp1[WORD_LEN+1];
      getword(temp1, WORD_LEN+1);
      strncpy(one_word_dict_t.line_one, temp1,WORD_LEN+1 );
      
      //reading line 2 
      getword(one_word_dict_t.line_two,MAX_NUM_POS_TAGS+1);//do something about spaces in between tags!
      
      
      //reading line 3
      
      getword(one_word_dict_t.line_three,SIZE_POS_TAG+VAR_FORM_LEN*SIZE_POS_TAG+1);
      
      //printing the word in the format:
      
      printf(&quot;==========================Stage 1==========================\n&quot;); 
      printf(&quot;Word 0: %s\n&quot;, one_word_dict_t.line_one);
      printf(&quot;POS: %s\n&quot;, one_word_dict_t.line_two);
      printf(&quot;Form: %s\n&quot;, one_word_dict_t.line_three);
      //stage 1 ends here 
      
      
  
  }
  
  //getword function def 
  /* Extract a single word out of the standard input, of not
     more than limit characters. Argument array W must be
     limit+1 characters or   bigger.    */
  int
  getword(char W[], int limit) 
  {
      int c, len=0;
      /* first, skip over any non alphabetics */
      while ((c=getchar())!=EOF &amp;&amp; !check_if_valid(c)) 
      {
          /* do nothing more */
      }
      if (c==EOF) 
      {
          return EOF;
      }
      /* ok, first character of next word has been found */
      W[len++] = c;
      while (len&lt;limit &amp;&amp; (c=getchar())!=EOF &amp;&amp; check_if_valid(c)) 
      {
          /* another character to be stored */
          W[len++] = c;
      }
      /* now close off the string */
      W[len] = '\0';
      return 0;
  }
  
  //check if valid function, used in modified version of getword():
  int check_if_valid(char in_char)
  {
      
      if ((('A'&lt;=in_char)&amp;&amp;(in_char&lt;='Z')) || (('a'&lt;=in_char)&amp;&amp;(in_char&lt;='z')) || 
          (('0'&lt;=in_char)&amp;&amp;(in_char&lt;='9')))
      
      {
          return 1;
      }
      
      else
      {
          return 0;
      }
          
      
  }
  </code></pre>