Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Winn32CRTconsole.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <locale.h>
- #include <stdlib.h>
- #include <search.h>
- struct List
- {
- _TCHAR f_name[15];
- _TCHAR s_name[15];
- _TCHAR l_name[15];
- _TCHAR group[4];
- int f_num;
- };
- int compare_fnum(const void* vptr1, const void* vptr2)
- {
- if (((struct List*)vptr1)->f_num > ((struct List*)vptr2)->f_num)
- return 1;
- if (((struct List*)vptr1)->f_num < ((struct List*)vptr2)->f_num)
- return -1;
- return 0;
- }
- int compare_group_then_sname(const void* vptr1, const void* vptr2)
- {
- if (_tcscmp(((struct List*)vptr1)->group, ((struct List*)vptr2)->group) == 0)
- return _tcscmp(((struct List*)vptr2)->s_name, ((struct List*)vptr1)->s_name);
- return _tcscmp(((struct List*)vptr1)->group, ((struct List*)vptr2)->group);
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- setlocale(LC_CTYPE, "en.UTF-8");
- struct List Arr[100];
- FILE* fp;
- if (_tfopen_s(&fp,argv[1], _T("r"))!= 0)
- printf("File opening failed!\n");
- int j = 0;
- while (feof(fp)==0)
- {
- _ftscanf(fp, _T("%s"), Arr[j].f_name);
- _ftscanf(fp, _T("%s"), Arr[j].s_name);
- _ftscanf(fp, _T("%s"), Arr[j].l_name);
- _ftscanf(fp, _T("%s"), Arr[j].group);
- fscanf(fp, "%d", &Arr[j].f_num);
- j++;
- }
- if (_ttoi(argv[2]) == 1)
- qsort(&Arr, j, sizeof(struct List), compare_fnum);
- if (_ttoi(argv[2]) == 2)
- qsort(&Arr, j, sizeof(struct List), compare_group_then_sname);
- for (int i = 0; i < j; i++)
- {
- _tprintf(_T("%s "), Arr[i].f_name);
- _tprintf(_T("%s "), Arr[i].s_name);
- _tprintf(_T("%s "), Arr[i].l_name);
- _tprintf(_T("%s "), Arr[i].group);
- printf("%d\n", Arr[i].f_num);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement