André123
asked on
file-question. easy.
hello.
I made this code:
-------------------
#include <iostream>
#include <windows.h>
using namespace std;
int main(){
FILE *Fp;
Fp = fopen("input.dat","r");
if (Fp == NULL) {
fprintf(stderr, "Can't open input file!\n");
exit(1);
}
-------------------
I have input.dat (version 1) located at:
"C:\\Program Files\\Microsoft Visual Studio\\MyProjects\\inleze nvanbestan d\\input.d at"
and my program is here:
"C:\\Program Files\\Microsoft Visual Studio\\MyProjects\\inleze nvanbestan d\\release \\aa.exe"
I have allso a input.dat (version 2) located here:
"C:\\Program Files\\Microsoft Visual Studio\\MyProjects\\inleze nvanbestan d\\release \\input.da t"
version 1 of input.dat is different from version 2.
The strange thing is:
when I run my program it opens version 1 of input.dat .
I want it to open the version in the directory of the exe (version 2).
so, my questions:
(1)-> How should I adapt the code so that it allways opens the file that is placed in the directory of the program itself (and, I don't want to have the file-pad "hardcoded" in the exe)
(2)-> How comes it opens the version 1 file ?? I don't think this is very logic , since it is placed one directory up !
Any advice is welcome...
Greetz, André.
I made this code:
-------------------
#include <iostream>
#include <windows.h>
using namespace std;
int main(){
FILE *Fp;
Fp = fopen("input.dat","r");
if (Fp == NULL) {
fprintf(stderr, "Can't open input file!\n");
exit(1);
}
-------------------
I have input.dat (version 1) located at:
"C:\\Program Files\\Microsoft Visual Studio\\MyProjects\\inleze
and my program is here:
"C:\\Program Files\\Microsoft Visual Studio\\MyProjects\\inleze
I have allso a input.dat (version 2) located here:
"C:\\Program Files\\Microsoft Visual Studio\\MyProjects\\inleze
version 1 of input.dat is different from version 2.
The strange thing is:
when I run my program it opens version 1 of input.dat .
I want it to open the version in the directory of the exe (version 2).
so, my questions:
(1)-> How should I adapt the code so that it allways opens the file that is placed in the directory of the program itself (and, I don't want to have the file-pad "hardcoded" in the exe)
(2)-> How comes it opens the version 1 file ?? I don't think this is very logic , since it is placed one directory up !
Any advice is welcome...
Greetz, André.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Tried it in some other folders and it opens the correct version if I don't run it from MSVC (so, from a cmd-promt).