Advertisement
Guest User

beta

a guest
May 22nd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <locale.h>
  4. #include <math.h>
  5. #include <windows.h>
  6. #include <string.h>
  7.  
  8. typedef struct {
  9. char surname[50];
  10. int number;
  11. double weight;
  12. } info;
  13.  
  14. int main() {
  15. setlocale(0, "");
  16. system("chcp 1251");
  17. system("cls");
  18.  
  19. FILE* f;
  20. int n, i;
  21. info human;
  22. char filename[50];
  23.  
  24. printf("Enter file name >> ");
  25. scanf("%s", filename);
  26.  
  27. if ((f = fopen(filename, "r")) == NULL) {
  28. f = fopen(filename, "a");
  29. printf("Enter number of members >> ");
  30. scanf("%d", n);
  31. for (i=0; i<n; i++) {
  32. printf("For member %d :\n", i);
  33. printf("Surname >> ");
  34. scanf("%s", human.surname);
  35. fprintf(f, "%s", human.surname);
  36. printf("Number. >> ");
  37. scanf("%d", human.number);
  38. fprintf(f, "%d", human.number);
  39. printf("Weight >> ");
  40. scanf("%lf", human.weight);
  41. fprintf(f, "%lf", human.weight);
  42. }
  43. printf("File %s was created!", filename);
  44. system("pause");
  45. }
  46. fclose(f);
  47. system("cls");
  48. f = fopen(filename, "r");
  49. while (!eof(f)) {
  50. fscanf(f, "%s%d%lf", human.surname, human.number, human.weight);
  51. printf("%2d | %10s | %4d | %5lf |\n",
  52. human.surname, human.number, human.weight);
  53. }
  54. system("pause");
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement