Need help with a file save

So the intention of this project was to basically play around with command prompt commands, however it seems that I've run into a file error.

The program uses "getmac" and stores it to a text file, however when I display this it generates random numbers at the bottom of it, and I can't figure out why.

Can anyone help? I've practically re-written the thing twice over!

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
//precompiler directives:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <math.h>
#include <windows.h>
#include <stdio.h>
#include <string>

using namespace std;

// protos
void newfile();
void writefile();


int main() {
	newfile();
}



void newfile(){
  ofstream pfile ("parsefile.txt");
  if (pfile.is_open()) { 
  }
  else
  pfile.close();
  writefile();
}

void writefile(){
	ofstream pfile ("parsefile.txt");
	string hold;
	hold = system("getmac");
	pfile<<hold;
	cout<<pfile;

	pfile.close();
	
	
}
Last edited on
http://www.cplusplus.com/reference/clibrary/cstdlib/system/
Once the command execution has terminated, the processor gives the control back to the program, returning an int value, whose interpretation is system-dependent.
In many systems, 0 is used to indicate that the command was successfully executed and other values to indicate some sort of error.

The program uses "getmac" and stores it to a text file
To do that you could simply $ getmac > out_file

system is evil http://www.cplusplus.com/articles/j3wTURfi/
Last edited on
I'm not familiar with that, I'm guessing I'd do this?


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
//precompiler directives:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <math.h>
#include <windows.h>
#include <stdio.h>
#include <string>

using namespace std;

// protos

void newfile();

void writefile();
int main() {
	newfile();

}

void newfile(){
  ofstream pfile ("parsefile.txt");
  if (pfile.is_open()) { 
  }
  else
  pfile.close();
  writefile();
}

void writefile(){
	ofstream pfile ("parsefile.txt");
        //change
        $ getmac > pfile;
       // /change?
	pfile<<hold;
	cout<<pfile;
	pfile.close();
}
Topic archived. No new replies allowed.