Tweeted twitter.com/StackCodeReview/status/744333054689280000
7 edited tags
| link
6 deleted 557 characters in body
source | link

Since this is my first project, I want its coding style to be reviewed most of all. Also, please let me know if adding register or restricted somewhere can be benefitial, for I want to learn more about the use of modifiers in C. Of course, other optimisations are appreciated too.

Since this is my first project, I want its coding style to be reviewed most of all. Of course, other optimisations are appreciated too.

Since this is my first project, I want its coding style to be reviewed most of all. Also, please let me know if adding register or restricted somewhere can be benefitial, for I want to learn more about the use of modifiers in C. Of course, other optimisations are appreciated too.

5 Fixed edit clash
source | link

In fact, this is the assignment of mya group assignment for our C programming lesson, but seeking help from others areis not considered as cheating. 

The goal of the following code is to:

  1. Sort the data in start.txt by destination, and then by month if two trip routes share one destination.
  2. Count how many trip routes each month and destination have.
  3. Output the sorted data and the statistics to result.txt.

HereSince this is my code:first project, I want its coding style to be reviewed most of all. Of course, other optimisations are appreciated too.

1   Guilin  7   Domestic    2   9857
2   Suzhou  7   Domestic    1   47893
3   Wuxi    3   Domestic    3   41525
4   Tibet   4   Domestic    4   13123
5   Guilin  5   Domestic    7   5532
6   Wuxi    6   Domestic    8   232
7   Suzhou  7   Domestic    9   132132
8   Wuxi    8   Domestic    4   343432
9   Suzhou  9   Domestic    12  24234
10  Jinan   10  Domestic    5   42334
11  Wuxi    7   Domestic    6   15156
12  Tibet   3   Domestic    10  25425
13  Tibet   4   Domestic    11  35345
14  Tibet   5   Domestic    12  34453
15  Suzhou  6   Domestic    3   34345
16  Jinan   7   Domestic    5   8785
17  Suzhou  8   Domestic    6   334533
18  Jinan   9   Domestic    7   4653
19  Wuxi    10  Domestic    9   34234
20  Wuxi    7   Domestic    10  2432423
21  Jinan   3   Domestic    1   43432
22  Tibet   4   Domestic    11  87678
23  Suzhou  5   Domestic    5   78878
24  Suzhou  6   Domestic    7   7826
25  Jinan   7   Domestic    12  2132
26  Tibet   8   Domestic    3   464656
27  Wuxi    9   Domestic    8   9857
28  Tibet   10  Domestic    9   47893
29  Tibet   7   Domestic    2   41525
30  Jinan   3   Domestic    6   13123
31  Suzhou  4   Domestic    7   5532
32  Guilin  5   Domestic    3   232
33  Guilin  6   Domestic    4   132132
34  Guilin  7   Domestic    5   343432
35  Wuxi    8   Domestic    9   24234
36  Guilin  9   Domestic    10  42334
37  Suzhou  10  Domestic    11  15156
38  Wuxi    7   Domestic    2   25425
39  Suzhou  3   Domestic    3   35345
40  Guilin  4   Domestic    6   34453
41  Munich  5   International       7   34345
42  Dubai   6   International       5   8785
43  London  7   International       6   334533
44  Paris   8   International       9   4653
45  Vienna  9   International       8   34234
46  Moscow  10  International       11  2432423
47  Berlin  7   International       12  43432
48  Tokyo   3   International       10  87678
49  Sydney  4   International       9   78878
50  Madrid  5   International       8   7826
51  Munich  6   International       7   2132
52  Dubai   7   International       6   464656
53  London  8   International       5   9857
54  Paris   9   International       4   47893
55  Vienna  10  International       7   41525
56  Moscow  7   International       5   13123
57  Berlin  3   International       3   5532
58  Tokyo   4   International       2   232
59  Sydney  5   International       1   132132
60  Madrid  6   International       4   343432
61  Munich  7   International       5   24234
62  Dubai   8   International       6   42334
63  London  9   International       7   15156
64  Paris   10  International       9   25425
65  Vienna  7   International       1   35345
66  Moscow  3   International       2   34453
67  Berlin  4   International       10  34345
68  Tokyo   5   International       11  8785
69  Sydney  6   International       12  334533
70  Madrid  7   International       11  4653
71  Munich  8   International       9   34234
72  Dubai   9   International       5   2432423
73  London  10  International       6   43432
74  Paris   7   International       7   87678
75  Vienna  3   International       2   78878
76  Moscow  4   International       3   7826
77  Berlin  5   International       4   2132
78  Tokyo   6   International       5   464656
79  Sydney  7   International       8   9857
80  Madrid  8   International       9   47893
81  Munich  9   International       10  41525
82  Dubai   10  International       3   13123
83  London  7   International       4   5532
84  Paris   3   International       5   232
85  Vienna  4   International       8   132132
86  Moscow  5   International       4   343432
87  Berlin  6   International       8   24234
88  Tokyo   7   International       1   42334
89  Sydney  8   International       7   15156
90  Madrid  9   International       7   25425
91  Munich  10  International       7   35345
92  Dubai   7   International       7   34453
93  London  3   International       4   34345
94  Paris   4   International       3   8785
95  Vienna  5   International       2   334533
96  Moscow  6   International       6   4653
97  Berlin  7   International       7   34234
98  Tokyo   8   International       9   2432423
99  Sydney  9   International       8   43432
100 Madrid  10  International       10  87678

Since this is my first project(although it's more of a toy project than a serious one), I want to its coding style to be reviewed most. Of course, other optimisations are appreciated too. Thanks in advance for your reviewing!

1 Guilin  7   Domestic    2   9857
2 Suzhou  7   Domestic    1   47893
3 Wuxi    3   Domestic    3   41525
4 Tibet   4   Domestic    4   13123
5 Guilin  5   Domestic    7   5532
6 Wuxi    6   Domestic    8   232
7 Suzhou  7   Domestic    9   132132
8 Wuxi    8   Domestic    4   343432
9 Suzhou  9   Domestic    12  24234
10    Jinan   10  Domestic    5   42334
11    Wuxi    7   Domestic    6   15156
12    Tibet   3   Domestic    10  25425
13    Tibet   4   Domestic    11  35345
14    Tibet   5   Domestic    12  34453
15    Suzhou  6   Domestic    3   34345
16    Jinan   7   Domestic    5   8785
17    Suzhou  8   Domestic    6   334533
18    Jinan   9   Domestic    7   4653
19    Wuxi    10  Domestic    9   34234
20    Wuxi    7   Domestic    10  2432423
21    Jinan   3   Domestic    1   43432
22    Tibet   4   Domestic    11  87678
23    Suzhou  5   Domestic    5   78878
24    Suzhou  6   Domestic    7   7826
25    Jinan   7   Domestic    12  2132
26    Tibet   8   Domestic    3   464656
27    Wuxi    9   Domestic    8   9857
28    Tibet   10  Domestic    9   47893
29    Tibet   7   Domestic    2   41525
30    Jinan   3   Domestic    6   13123
31    Suzhou  4   Domestic    7   5532
32    Guilin  5   Domestic    3   232
33    Guilin  6   Domestic    4   132132
34    Guilin  7   Domestic    5   343432
35    Wuxi    8   Domestic    9   24234
36    Guilin  9   Domestic    10  42334
37    Suzhou  10  Domestic    11  15156
38    Wuxi    7   Domestic    2   25425
39    Suzhou  3   Domestic    3   35345
40    Guilin  4   Domestic    6   34453
41    Munich  5   International       7   34345
42    Dubai   6   International       5   8785
43    London  7   International       6   334533
44    Paris   8   International       9   4653
45    Vienna  9   International       8   34234
46    Moscow  10  International       11  2432423
47    Berlin  7   International       12  43432
48    Tokyo   3   International       10  87678
49    Sydney  4   International       9   78878
50    Madrid  5   International       8   7826
51    Munich  6   International       7   2132
52    Dubai   7   International       6   464656
53    London  8   International       5   9857
54    Paris   9   International       4   47893
55    Vienna  10  International       7   41525
56    Moscow  7   International       5   13123
57    Berlin  3   International       3   5532
58    Tokyo   4   International       2   232
59    Sydney  5   International       1   132132
60    Madrid  6   International       4   343432
61    Munich  7   International       5   24234
62    Dubai   8   International       6   42334
63    London  9   International       7   15156
64    Paris   10  International       9   25425
65    Vienna  7   International       1   35345
66    Moscow  3   International       2   34453
67    Berlin  4   International       10  34345
68    Tokyo   5   International       11  8785
69    Sydney  6   International       12  334533
70    Madrid  7   International       11  4653
71    Munich  8   International       9   34234
72    Dubai   9   International       5   2432423
73    London  10  International       6   43432
74    Paris   7   International       7   87678
75    Vienna  3   International       2   78878
76    Moscow  4   International       3   7826
77    Berlin  5   International       4   2132
78    Tokyo   6   International       5   464656
79    Sydney  7   International       8   9857
80    Madrid  8   International       9   47893
81    Munich  9   International       10  41525
82    Dubai   10  International       3   13123
83    London  7   International       4   5532
84    Paris   3   International       5   232
85    Vienna  4   International       8   132132
86    Moscow  5   International       4   343432
87    Berlin  6   International       8   24234
88    Tokyo   7   International       1   42334
89    Sydney  8   International       7   15156
90    Madrid  9   International       7   25425
91    Munich  10  International       7   35345
92    Dubai   7   International       7   34453
93    London  3   International       4   34345
94    Paris   4   International       3   8785
95    Vienna  5   International       2   334533
96    Moscow  6   International       6   4653
97    Berlin  7   International       7   34234
98    Tokyo   8   International       9   2432423
99    Sydney  9   International       8   43432
100   Madrid  10  International       10  87678

In fact, this is the assignment of my group for our C programming lesson, but seeking help from others are not considered as cheating. The goal of the following code is to:

  1. Sort the data in start.txt by destination, and then by month if two trip routes share one destination.
  2. Count how many trip routes each month and destination have.
  3. Output the sorted data and the statistics to result.txt

Here is my code:

1   Guilin  7   Domestic    2   9857
2   Suzhou  7   Domestic    1   47893
3   Wuxi    3   Domestic    3   41525
4   Tibet   4   Domestic    4   13123
5   Guilin  5   Domestic    7   5532
6   Wuxi    6   Domestic    8   232
7   Suzhou  7   Domestic    9   132132
8   Wuxi    8   Domestic    4   343432
9   Suzhou  9   Domestic    12  24234
10  Jinan   10  Domestic    5   42334
11  Wuxi    7   Domestic    6   15156
12  Tibet   3   Domestic    10  25425
13  Tibet   4   Domestic    11  35345
14  Tibet   5   Domestic    12  34453
15  Suzhou  6   Domestic    3   34345
16  Jinan   7   Domestic    5   8785
17  Suzhou  8   Domestic    6   334533
18  Jinan   9   Domestic    7   4653
19  Wuxi    10  Domestic    9   34234
20  Wuxi    7   Domestic    10  2432423
21  Jinan   3   Domestic    1   43432
22  Tibet   4   Domestic    11  87678
23  Suzhou  5   Domestic    5   78878
24  Suzhou  6   Domestic    7   7826
25  Jinan   7   Domestic    12  2132
26  Tibet   8   Domestic    3   464656
27  Wuxi    9   Domestic    8   9857
28  Tibet   10  Domestic    9   47893
29  Tibet   7   Domestic    2   41525
30  Jinan   3   Domestic    6   13123
31  Suzhou  4   Domestic    7   5532
32  Guilin  5   Domestic    3   232
33  Guilin  6   Domestic    4   132132
34  Guilin  7   Domestic    5   343432
35  Wuxi    8   Domestic    9   24234
36  Guilin  9   Domestic    10  42334
37  Suzhou  10  Domestic    11  15156
38  Wuxi    7   Domestic    2   25425
39  Suzhou  3   Domestic    3   35345
40  Guilin  4   Domestic    6   34453
41  Munich  5   International       7   34345
42  Dubai   6   International       5   8785
43  London  7   International       6   334533
44  Paris   8   International       9   4653
45  Vienna  9   International       8   34234
46  Moscow  10  International       11  2432423
47  Berlin  7   International       12  43432
48  Tokyo   3   International       10  87678
49  Sydney  4   International       9   78878
50  Madrid  5   International       8   7826
51  Munich  6   International       7   2132
52  Dubai   7   International       6   464656
53  London  8   International       5   9857
54  Paris   9   International       4   47893
55  Vienna  10  International       7   41525
56  Moscow  7   International       5   13123
57  Berlin  3   International       3   5532
58  Tokyo   4   International       2   232
59  Sydney  5   International       1   132132
60  Madrid  6   International       4   343432
61  Munich  7   International       5   24234
62  Dubai   8   International       6   42334
63  London  9   International       7   15156
64  Paris   10  International       9   25425
65  Vienna  7   International       1   35345
66  Moscow  3   International       2   34453
67  Berlin  4   International       10  34345
68  Tokyo   5   International       11  8785
69  Sydney  6   International       12  334533
70  Madrid  7   International       11  4653
71  Munich  8   International       9   34234
72  Dubai   9   International       5   2432423
73  London  10  International       6   43432
74  Paris   7   International       7   87678
75  Vienna  3   International       2   78878
76  Moscow  4   International       3   7826
77  Berlin  5   International       4   2132
78  Tokyo   6   International       5   464656
79  Sydney  7   International       8   9857
80  Madrid  8   International       9   47893
81  Munich  9   International       10  41525
82  Dubai   10  International       3   13123
83  London  7   International       4   5532
84  Paris   3   International       5   232
85  Vienna  4   International       8   132132
86  Moscow  5   International       4   343432
87  Berlin  6   International       8   24234
88  Tokyo   7   International       1   42334
89  Sydney  8   International       7   15156
90  Madrid  9   International       7   25425
91  Munich  10  International       7   35345
92  Dubai   7   International       7   34453
93  London  3   International       4   34345
94  Paris   4   International       3   8785
95  Vienna  5   International       2   334533
96  Moscow  6   International       6   4653
97  Berlin  7   International       7   34234
98  Tokyo   8   International       9   2432423
99  Sydney  9   International       8   43432
100 Madrid  10  International       10  87678

Since this is my first project(although it's more of a toy project than a serious one), I want to its coding style to be reviewed most. Of course, other optimisations are appreciated too. Thanks in advance for your reviewing!

In fact, this is a group assignment for our C programming lesson, but seeking help from others is not considered cheating. 

The goal of the following code is to:

  1. Sort the data in start.txt by destination, and then by month if two trip routes share one destination.
  2. Count how many trip routes each month and destination have.
  3. Output the sorted data and the statistics to result.txt.

Since this is my first project, I want its coding style to be reviewed most of all. Of course, other optimisations are appreciated too.

1 Guilin  7   Domestic    2   9857
2 Suzhou  7   Domestic    1   47893
3 Wuxi    3   Domestic    3   41525
4 Tibet   4   Domestic    4   13123
5 Guilin  5   Domestic    7   5532
6 Wuxi    6   Domestic    8   232
7 Suzhou  7   Domestic    9   132132
8 Wuxi    8   Domestic    4   343432
9 Suzhou  9   Domestic    12  24234
10    Jinan   10  Domestic    5   42334
11    Wuxi    7   Domestic    6   15156
12    Tibet   3   Domestic    10  25425
13    Tibet   4   Domestic    11  35345
14    Tibet   5   Domestic    12  34453
15    Suzhou  6   Domestic    3   34345
16    Jinan   7   Domestic    5   8785
17    Suzhou  8   Domestic    6   334533
18    Jinan   9   Domestic    7   4653
19    Wuxi    10  Domestic    9   34234
20    Wuxi    7   Domestic    10  2432423
21    Jinan   3   Domestic    1   43432
22    Tibet   4   Domestic    11  87678
23    Suzhou  5   Domestic    5   78878
24    Suzhou  6   Domestic    7   7826
25    Jinan   7   Domestic    12  2132
26    Tibet   8   Domestic    3   464656
27    Wuxi    9   Domestic    8   9857
28    Tibet   10  Domestic    9   47893
29    Tibet   7   Domestic    2   41525
30    Jinan   3   Domestic    6   13123
31    Suzhou  4   Domestic    7   5532
32    Guilin  5   Domestic    3   232
33    Guilin  6   Domestic    4   132132
34    Guilin  7   Domestic    5   343432
35    Wuxi    8   Domestic    9   24234
36    Guilin  9   Domestic    10  42334
37    Suzhou  10  Domestic    11  15156
38    Wuxi    7   Domestic    2   25425
39    Suzhou  3   Domestic    3   35345
40    Guilin  4   Domestic    6   34453
41    Munich  5   International       7   34345
42    Dubai   6   International       5   8785
43    London  7   International       6   334533
44    Paris   8   International       9   4653
45    Vienna  9   International       8   34234
46    Moscow  10  International       11  2432423
47    Berlin  7   International       12  43432
48    Tokyo   3   International       10  87678
49    Sydney  4   International       9   78878
50    Madrid  5   International       8   7826
51    Munich  6   International       7   2132
52    Dubai   7   International       6   464656
53    London  8   International       5   9857
54    Paris   9   International       4   47893
55    Vienna  10  International       7   41525
56    Moscow  7   International       5   13123
57    Berlin  3   International       3   5532
58    Tokyo   4   International       2   232
59    Sydney  5   International       1   132132
60    Madrid  6   International       4   343432
61    Munich  7   International       5   24234
62    Dubai   8   International       6   42334
63    London  9   International       7   15156
64    Paris   10  International       9   25425
65    Vienna  7   International       1   35345
66    Moscow  3   International       2   34453
67    Berlin  4   International       10  34345
68    Tokyo   5   International       11  8785
69    Sydney  6   International       12  334533
70    Madrid  7   International       11  4653
71    Munich  8   International       9   34234
72    Dubai   9   International       5   2432423
73    London  10  International       6   43432
74    Paris   7   International       7   87678
75    Vienna  3   International       2   78878
76    Moscow  4   International       3   7826
77    Berlin  5   International       4   2132
78    Tokyo   6   International       5   464656
79    Sydney  7   International       8   9857
80    Madrid  8   International       9   47893
81    Munich  9   International       10  41525
82    Dubai   10  International       3   13123
83    London  7   International       4   5532
84    Paris   3   International       5   232
85    Vienna  4   International       8   132132
86    Moscow  5   International       4   343432
87    Berlin  6   International       8   24234
88    Tokyo   7   International       1   42334
89    Sydney  8   International       7   15156
90    Madrid  9   International       7   25425
91    Munich  10  International       7   35345
92    Dubai   7   International       7   34453
93    London  3   International       4   34345
94    Paris   4   International       3   8785
95    Vienna  5   International       2   334533
96    Moscow  6   International       6   4653
97    Berlin  7   International       7   34234
98    Tokyo   8   International       9   2432423
99    Sydney  9   International       8   43432
100   Madrid  10  International       10  87678
4 deleted 120 characters in body; edited title
source | link
3 added 176 characters in body
source | link
2 added 3075 characters in body
source | link
1
source | link