Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "stdio.h"
- #include "string.h"
- #include "windows.h"
- #define _CRT_SECURE_NO_WARNINGS
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- struct list
- {
- char name[100];
- int number;
- char group[100];
- };
- char s[100];
- int count,countconst;
- int size1=0, size2=0;
- int i,j;
- struct list temp;
- struct list mas[10];
- FILE *f1;
- f1 = fopen("1.txt", "r");
- while (!feof(f1))
- {
- fgets(s, 100, f1);
- size1++;
- count = strlen(s);
- while (s[count] != ' ')
- count--;
- countconst = count;
- for (i = 0; i < 6; i++)
- {
- mas[size1 - 1].group[i] = s[count + 1];
- count++;
- }
- mas[size1 - 1].group[6] = '\0';
- for (i = 0; i < countconst; i++)
- {
- mas[size1 - 1].name[i] = s[i];
- }
- mas[size1 - 1].name[countconst] = '\0';
- }
- fclose(f1);
- FILE *f2;
- f2 = fopen("2.txt", "r");
- while (!feof(f2))
- {
- fgets(s, 100, f1);
- size1++;
- count = strlen(s);
- while (s[count] != ' ')
- count--;
- countconst = count;
- for (i = 0; i < 6; i++)
- {
- mas[size1 - 1].group[i] = s[count + 1];
- count++;
- }
- mas[size1 - 1].group[6] = '\0';
- for (i = 0; i < countconst; i++)
- {
- mas[size1 - 1].name[i] = s[i];
- }
- mas[size1 - 1].name[countconst] = '\0';
- }
- fclose(f2);
- for (i = 0; i<size1 - 1; i++)
- for (j = size1 - 2; j >= i; j--)
- if (strcmp(mas[j].name, mas[j + 1].name)>0)
- {
- temp = mas[j];
- mas[j] = mas[j + 1];
- mas[j + 1] = temp;
- }
- FILE *f3;
- f3 = fopen("result.txt","w");
- for (i = 0; i < size1; i++)
- {
- mas[i].number = i + 1;
- fprintf(f1, "%d ", mas[i].number);
- fprintf(f1, "%s ", mas[i].name);
- fprintf(f1, "%s\n", mas[i].group);
- }
- fclose(f3);
- system("pause");
- }
Add Comment
Please, Sign In to add comment