Почему программа пропускает первый gets в цикле for в си

#include <stdio.h>
#include <stdlib.h>
struct university
{
  char thedepartment[20];
  char chief[20];
  char stream[100];
  int value;
};
int main()
{
  int j;
  printf("Enter the number of departments: ");
  scanf("%d", &j);
  struct university libry[j+1];
  int i;
  int k;
  for (i = 0; i<j-1; i++)
  {
    printf("Enter the name of the department : " );
    gets(libry[i].thedepartment);
    printf("Enter chief`s name : " );
    gets(libry[i].chief);
    printf("Enter the number of streams : " );
    gets(libry[i].stream);
    printf("Enter the number of employees : " );
    scanf("%d", &libry[i].value);
    getchar();
  }
   printf("Enter the number of employees:");
    scanf("%d", &k);
  for (i = 0; i<j; i++) {
   if (k < libry[i].value ) {
     printf("\n %d. %s ", i + 1, libry[i].chief);
    printf("%s %s, %d", libry[i].thedepartment, libry[i].stream ,libry[i].value);
   }
  }
  getchar();
  return 0;
}

При компиляции выдает " Enter the number of departments: 2 Enter the name of the department : Enter chief`s name : " Совмещая две строки, догадываюсь что проблема в пробеге по циклу , но где именно?


Ответы (0 шт):