#include <stdio.h>
#include <stdlib.h>
struct ogrenci{
char *ad[20];
char *soyad[20];
char *bolum[20];
int sinif;
int sinav1;
int sinav2;
float NOTort;
};
int main()
{
FILE *fp;
struct ogrenci ogr;
int n, toplam=0;
if((fp =fopen("bilgi.txt", "a+"))==NULL){
puts("Ogrenci bilgi dosyasi bulunamadi");
exit(1);
}
printf("Lutfen ogrenci sayisini giriniz:");
scanf("%d", &n);
// Hafızadan dinamik bellek ayırtmak.
fp=calloc(n, sizeof(struct ogrenci));
//fprintf(fp, "Adi\tSoyadi \tBolum \tSinifi \tSinav1 \tSinav2 \tOrt\n");
while(n>0)
{
printf("Ogrenci ad: ");
scanf("%s",ogr.ad);
printf("Ogrenci soyadi: ");
scanf("%s",ogr.soyad);
printf("Ogrenci bolum: ");
scanf("%s",ogr.bolum);
printf("Ogrenci sinifi: ");
scanf("%d",&ogr.sinif);
printf("Ogrenci sinavi1: ");
scanf("%d",&ogr.sinav1);
printf("Ogrenci sinavi2: ");
scanf("%d",&ogr.sinav2);
toplam = (ogr.sinav1 + ogr.sinav2);
ogr.NOTort = (float)toplam /2;
fprintf(fp, "%s\t%s\t%s\t%d\t%d\t%3\t%.2f\n", ogr.ad, ogr.soyad, ogr.bolum, ogr.sinif, ogr.sinav1, ogr.sinav2, ogr.NOTort);
n--;
}
fclose(fp);
return 0;
}
Hiç yorum yok:
Yorum Gönder