Ben de aşağıdaki ifade uyarı yükseltiyor.
scanf("%s %d %d %s", &a.isim, &a.ogrenci_sayi, &a.ogretmen_sayi, &a.sehir);
Uyarı da şöyle:
a.c: In function ‘main’:
a.c:14:10: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[15]’ [-Wformat=]
scanf("%s %d %d %s", &a.isim, &a.ogrenci_sayi, &a.ogretmen_sayi, &a.sehir);
~^ ~~~~~~~
a.c:14:19: warning: format ‘%s’ expects argument of type ‘char *’, but argument 5 has type ‘char (*)[10]’ [-Wformat=]
scanf("%s %d %d %s", &a.isim, &a.ogrenci_sayi, &a.ogretmen_sayi, &a.sehir);
Bu yukarıdaki yerine şöyle yapınca uyarı almıyorum.
scanf("%s %d %d %s", a.isim, &a.ogrenci_sayi, &a.ogretmen_sayi, a.sehir);
Aynı durum for
döngüsündeki scanf
için de geçerli. &c[i].isim
yerine c[i].isim
ve &c[i].sehir
yerine c[i].sehir
yazınca uyarı almıyorum.
Bunun nedeni ne?
Bende uyarı vermeyen kodlar şu şekilde:
#include <stdio.h>
struct okul_yapisi {
char isim[15];
int ogrenci_sayi;
int ogretmen_sayi;
char sehir[10];
};
int main() {
typedef struct okul_yapisi okul_yapisi;
okul_yapisi a, *b, c[10];
scanf(
"%s %d %d %s",
a.isim, &a.ogrenci_sayi, &a.ogretmen_sayi, a.sehir
);
for(int i = 0; i < 1; i++){
scanf(
"%s %d %d %s",
c[i].isim, &c[i].ogrenci_sayi, &c[i].ogretmen_sayi, c[i].sehir
);
}
b = &a;
printf("b'nin değeri:\n");
printf(
"isim: %s ogrenci sayi: %d ogretmen sayi %d sehir: %s\n",
b->isim, b->ogrenci_sayi, b->ogretmen_sayi, b->sehir
);
printf("c'nin değeri:\n");
for(int i = 0; i < 1; i++){
printf(
"isim: %s ogrenci sayi: %d ogretmen sayi: %d sehir: %s\n",
c[i].isim, c[i].ogrenci_sayi, c[i].ogretmen_sayi, c[i].sehir
);
}
return 0;
}