Advertisement
thienlang

Nhập FILE- C

Dec 4th, 2013
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS 0
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <string.h>
  5. #include <time.h>
  6. #include <stdlib.h>
  7.  
  8.  
  9. struct SV
  10. {
  11.         char HoTen[30];
  12.         int Diem;
  13. };
  14.  
  15. void nhap1SV(SV &SinhVien)
  16. {
  17.         printf("Nhap vao ten SV: ");
  18.         gets(SinhVien.HoTen);
  19.         srand((unsigned) time(NULL));
  20.         SinhVien.Diem=rand()%11;
  21. }
  22. void luuDanhSach(SV SinhVien, FILE* fp)
  23. {
  24.        
  25.         if (fp!=NULL)
  26.         {
  27.                 fprintf(fp,"%s  %i\n",SinhVien.HoTen, SinhVien.Diem);
  28.         }
  29. }
  30.  
  31. void main()
  32. {
  33.         SV DanhSachSV[3];
  34.         FILE *fp=fopen("DanhSachSV.txt","wt");
  35.         for (int i=0; i<3; i++)
  36.         {
  37.                 nhap1SV(DanhSachSV[i]);
  38.                 luuDanhSach(DanhSachSV[i],fp);
  39.         }
  40.         fclose(fp);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement