Link to home
Start Free TrialLog in
Avatar of André123
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\\inlezenvanbestand\\input.dat"

and my program is here:
"C:\\Program Files\\Microsoft Visual Studio\\MyProjects\\inlezenvanbestand\\release\\aa.exe"

I have allso a input.dat (version 2) located here:
"C:\\Program Files\\Microsoft Visual Studio\\MyProjects\\inlezenvanbestand\\release\\input.dat"
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
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of André123
André123

ASKER

thanks both.

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).