Reading from .dat and writing to .txt

So I'm in a C++ class (mostly taught in C though) and I'm falling behind I guess because I'm completely lost on how to do my project.

I need to be able to read in a .dat file, some how take the data out of it (without using an array) then write it to a .txt file in the format he wants (table with mean, range, average, ect. of the numbers in .dat).

He gave us some code to use for reading the .dat but I can't get it to work. I put it in my project and when I type the name of the .dat file (in this case one.dat) it says could not read, closing. I put the one.dat into the debug folder with the .exe and it still can't read the damn file.

I also don't know how to write to the .txt after I read the info in and do all the math I need to do.

Using Visual Studio C++ Express 2010 if that makes a difference.

link to project encase you don't know what I'm looking for:
http://faculty.edcc.edu/paul.bladek/CS131/p2.htm

Code he gave us for read:

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
  #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <conio.h>
/*
*/

int main(int argc, char *argv[])
{
	FILE * inFileHandle = NULL;
	FILE * outFileHandle = NULL;
	char filename[FILENAME_MAX];
	char c = ' ';

	if(argc > 1)
	{
		strncpy(filename, argv[1], FILENAME_MAX);
	}
	else
	{
		puts("Enter the name of the file to read (source):");
		fgets(filename, FILENAME_MAX, stdin);
		if(filename[strlen(filename) - 1] == '\n')
			filename[strlen(filename) - 1] = '\0';
		else
			while(getchar() != '\n')
				;
	}
	
	inFileHandle = fopen(filename, "r");
	if(inFileHandle == NULL)
	{
		printf("Could not open file %s for input.\n"
			"Press any key to Continue", filename );
		getch();
		return EXIT_FAILURE;
	}
	if(argc > 2)
	{
		strncpy(filename, argv[2], FILENAME_MAX);
	}
	else
	{
		puts("Enter the name of the file to write (output):");
		gets(filename); // not safe! (potential buffer overflow)
	}

	outFileHandle = fopen(filename, "a");
	if(outFileHandle == NULL)
	{
		fclose(inFileHandle);
		printf("Could not open file %s for output.\n"
			"Press any key to Continue", filename );
		getch();
		return EXIT_FAILURE;
	}

	while((c = (char)getc(inFileHandle)) != EOF)
	{
		if(c == ' ')
			c = '\n';
		putc(c, outFileHandle);
	}
	fclose(inFileHandle);
	fclose(outFileHandle);
	puts("\nPress any key to Continue");
	getch();
	return EXIT_SUCCESS;
}


Obviously not looking for to have it done for me, just really need some help and explanation as to what I'm doing with all this.
Bump? Hoping I can get some help soon on this.
The file needs to be in the workspace folder (where you have your project file) and not inside the debug folder. Try putting there and then try to open it.
Damn it, I realized that was probably it this morning when it was too late.

Once it's loaded how do I get the info out of the file without an array?

The data will look like this:

2
3 7
4
5 9 2 7
3
5 3 1


Odd lines show number of numbers in even line following it. Need to output a .txt with range of numbers, average of numbers, mean of numbers, and ect.
Never mind, still don't know how. Where do I put it? Tried loading into the resources in VB2010, in debug with the exe and in the project root folder....
Alright so now I found out it's Visual Studios problem. If I run the program from the .exe in the debug and put my .dat files in there it reads perfectly. But if I run it through VS first it can't find the files. Now I just need to learn what to do with the damn numbers in the file.
Read in number then do a loop and run it for that number of times then repeat
Don't know if I mentioned but I'm very new to C++. I don't fully know what you mean. I know what a loop is but not sure how to go about reading data in using it.
That dat file can be anything from just:
1
5

to

2
3 7
4
5 9 2 7
3
5 3 1


Need to store the numbers in variables from smallest variable to biggest to sums of the numbers. I kind of know how to do that with an if else statement but don't know how to start the loop reading numbers, skipping every other line kind of.

What the teacher gave us for info on how it should work:

The program should be fully planned in advance. It should be well documented, and work correctly.
If the input file dat1.dat looks like this:

5
5 7 3 6 6
2
2 5
Then the output file should look something like:
The results from file dat1.dat are:
_____________________________________________________________________
|# of data| sum | range | mean | variance | standard deviation|
_____________________________________________________________________
| 5| 27| 3 to 7| 5.400| 2.300| 1.517 |
_____________________________________________________________________
| 7| 34| 2 to 7| 4.857| 3.143| 1.773 |
_____________________________________________________________________
Notice that the addition of 2 new pieces of data shows in the results as a total of 7.

Bump, even though I'm not sure this forum works with bumps.
Topic archived. No new replies allowed.