Reversing Values - Few Problems

Hi guys, I'm still pretty much a beginner on c++. Basically, i've got a random number generator and it gives me pressure values, which are written to a file named Results.txt , from here I need to write the information from the Results file to a file named Data2.txt but in reverse order. I also need to need to work out how to swap the order in which the columns are stored in the Data2.txt file. And to sort and store the values of each column in ascending order. Any help would be much appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<vector>

void main ()

{
	
float grippertop, gripperbottom, sensor;
int response, reply, reply2, pressure;

FILE *Results;
FILE *Data2;
int i, n, ans;
int count=0;


if ((Results = fopen("E:\\Results.txt", "r+"))==NULL)

	{
		printf("Error opening file\n");
		//exit(1); 

	}	

fprintf(Results,"Pressure of Columns\n\n");


  printf("Performing check to ensure Robot is attached to Column\n\n");
 
	srand ( time(NULL) );
	response=rand() % 2;


	if (response==0)
	{ 
		printf("Robot is not attached to Column, Deploying grippers.\n\n");

	}

	else if (response==1)
	{ 
		printf("Robot is attached to column.\n\n");
	}



	do
	{


		do
		{
			printf ("Robot is now attached and in position at the Bottom of the Column.\n\n");
			printf ("Would you like the Bottom Gripper to advance to the Centre of the Column?");
			printf (" Press '0' for No & '1' for Yes.\n\n");
			scanf("%d",&reply);

			if (reply>1)
			{
				printf("Reply must be either '0' or '1'.\n");
			}

			else if (reply==0)
			{ 
				printf("Bottom Gripper has not moved.\n");
				printf("Ending program.");
		
				fflush(stdin);
				getchar();	

				exit(0);
			
			}

			else if (reply==1)
			{
				printf("Bottom Gripper has advanced to the Centre of the Column.\n\n");
			}

			printf("Checking the Pressure of the Column ... \n\n");

			srand ( time(NULL) );
			pressure=rand() % 61;
			printf("The Pressure of the Column: %d\n\n", pressure);
			
			fprintf(Results, "%d\n",pressure);

			// think the reverse function needs to go around here

			fprintf(Data2, "%d\n",pressure);


			if (pressure>40)
			{
				printf("The pressure of this Column is fine.");
				fprintf(Results,"Not Welded\n\n");

			}
			else if (pressure<40)
			{
				printf("The pressure of this Column is unsatisfactory.\n\n");
				printf("Initialising Welding tool.\n\n");
				printf("Welding completed, Pressure level is now fine.\n\n");
				fprintf(Results,"Column Welded\n\n");

			}	


			do
			{


				printf("Would you like to advance to the next column? Press '0' for No & '1' for Yes.\n\n");
				scanf("%d",&reply);
				if (reply>1)
				{
					printf("Reply must be either '0' or '1'.\n\n");

				}

			}	while(reply>1);
	
			if (reply==0)

			{ 
				printf("Robot has not moved and is awaiting further instruction.\n\n");
		
				do
				{
					printf("Press '0' to End the Program or '1' to Move to the Next Column.\n\n");
					scanf("%d",&reply2);

					if (reply2>1)

					{
						printf("Reply must be either '0' or '1'.\n\n");

					}
				}
				while(reply2>1);
		
	
				if (reply2==0)

				{
					printf("Ending program.");
		
					fflush(stdin);
					getchar();	

					exit(0);

				}
			}
	
			else if ((reply==1) || (reply2==1))
			{
				printf("Robot is moving down the Column\n\n");
				printf("Robot has now dismounted itself from Current Column\n\n");
				printf("Robot is preparing to attach to next Column\n\n");	
		
				fflush(stdin);
				count++;
			}
		}
		while(count<20&&count++);
	}
	while(count<20&&count++);

	
	fclose(Results);
	
}
Bump, can anyone help please?
You already included the <vector> why not use it? IMO it's easier to store the results in a vector first, sort it using <algorithm> and sort(), then print it later to the files, use the reverse iterator to print the vector in reverse.
ref:
http://www.cplusplus.com/reference/stl/vector/
http://www.cplusplus.com/reference/algorithm/sort/

extra: stop declaring void main(), it's not standard, the same too with using the *.h libraries -the C standard headers that are used in C++ are these: http://www.cplusplus.com/reference/clibrary/ (same functions only the headers are named with 'c' prefix e.g <cstdio>
Topic archived. No new replies allowed.