title: C Struct Array Input
body: <p>I have the following struct</p>
  
  <pre><code>typedef char String[256];
  
  typedef struct
  {
      String name;
      int year;
      float price;
  } Book;
  </code></pre>
  
  <p>Array of Books</p>
  
  <pre><code>int main(int argc, const char * argv[])
  {    
      Book books[5];
  
      for (int i=0; i&lt;5; i++) {
          books[i] = inputBook();
      }
  
      return 0;
  }
  </code></pre>
  
  <p>inputBook() function</p>
  
  <pre><code>Book inputBook()
  {
      Book myBook;
  
      //Name
      puts("Enter Book Name:");
      gets(myBook.name);
  
      //Publishing Year
      puts("Enter Book Publishing Year:");
      scanf("%i", &amp;myBook.year);
  
      //Price
      puts("Enter Book Price:");
      scanf("%f", &amp;myBook.price);
  
      return myBook;
  }
  </code></pre>
  
  <p>For some reason the first book input is going well but when trying to input the second book and the second call to <code>inputBook()</code> I can set a book name, it jumps straight to the year import.</p>
  
  <p>What is the problem ?</p>
  
  <p>Thanks!</p>