Problem z gets dla tablicy struktur

0

Witam

 
#include <stdio.h>
#include <stdlib.h>
typedef struct student
{
    char imie[20];
    float srednia;
}Student;

int main()
{
    printf("Podaj liczbe studnetow \n");
    int n;
    scanf("%d",&n);
    Student c[n];
    int i=0;
    for(i;i<n;i++)
    {
        printf("Podaj imie studenta\n");
        gets(c[i].imie);
        printf("Podaj srednia studenta\n");
        scanf("%f",&c[i].srednia);
    }
    return 0;
}

Dlaczego mi nie pobiera imienia ? Próbowałem z fgets i też nie działa. Proszę o pomoc.

0
   for(i=0;i<n;i++)
    {
        printf("Podaj imie studenta\n");
        scanf("%s",&c[i].imie);
        printf("Podaj srednia studenta\n");
        scanf("%f",&c[i].srednia);
    }
0
#include <stdio.h>
#include <stdlib.h>

typedef struct
  {
   char imie[20];
   float srednia;
  } Student;
 
int main()
  {
   printf("Podaj liczbe studnetow: "); // użytkownik czyta tylko ten wiersz gdzie mruga kursor
   unsigned n; // int - przewiduje ujemną liczbę studentów
   scanf("%u",&n);
   Student c[n]; // powinno być Student *c=(Student*)malloc(n*sizeof(Student)); konstrukcja Student c[n]; działa ale w wąskim gronie kompilatorów
   for(unsigned i=0;i<n;++i) // nie używaj bezmyślnie i++ lepiej ++i bo sporo ci to będzie kosztować
     {
      printf("Podaj imie studenta: ");
      scanf(" %19s",c[i].imie); // nigdy nie stosuj gets - bo to pomyłka twórców, %s zawsze stosuj z maksymalnym rozmiarem
      printf("Podaj srednia studenta: ");
      scanf(" %f",&c[i].srednia);
     }
   for(unsigned i=0;i<n;++i) printf("%19s %f\n",c[i].imie,c[i].srednia);
   return 0;
  }

1 użytkowników online, w tym zalogowanych: 0, gości: 1