Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <locale.h>
- #include <math.h>
- #include <windows.h>
- #include <string.h>
- typedef struct {
- char surname[50];
- int number;
- double weight;
- } info;
- int main() {
- setlocale(0, "");
- system("chcp 1251");
- system("cls");
- FILE* f;
- int n, i;
- info human;
- char filename[50];
- printf("Enter file name >> ");
- scanf("%s", filename);
- if ((f = fopen(filename, "r")) == NULL) {
- f = fopen(filename, "a");
- printf("Enter number of members >> ");
- scanf("%d", n);
- for (i=0; i<n; i++) {
- printf("For member %d :\n", i);
- printf("Surname >> ");
- scanf("%s", human.surname);
- fprintf(f, "%s", human.surname);
- printf("Number. >> ");
- scanf("%d", human.number);
- fprintf(f, "%d", human.number);
- printf("Weight >> ");
- scanf("%lf", human.weight);
- fprintf(f, "%lf", human.weight);
- }
- printf("File %s was created!", filename);
- system("pause");
- }
- fclose(f);
- system("cls");
- f = fopen(filename, "r");
- while (!eof(f)) {
- fscanf(f, "%s%d%lf", human.surname, human.number, human.weight);
- printf("%2d | %10s | %4d | %5lf |\n",
- human.surname, human.number, human.weight);
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement