0

I try to use freopen ("inputString.txt","r",stdin); to send input to standard input.If I run program in eclipse the output is xxx but if I run program directly (run *.exe after compile without eclipse) the output is goodxxx

The text file is in the same directory of *.exe in eclipse project. How can I fix this. Here is some of my sourcecode.

 int main() {
int debug = 1,width,height;
char s[1000];
freopen ("inputString.txt","r",stdin);

s[0]='x';
scanf("%s",s);
printf("%s",s);
printf("xxx")for(;;);;

return 0;}

inputString.txt contain

good

UmAnusorn
  • 10,420
  • 10
  • 72
  • 100

3 Answers3

2

Check the current directory in your launch configuration, make sure it's what you expect. You can also use this to get and print the current directory from within your program to see where you are.

Community
  • 1
  • 1
Francis Upton IV
  • 19,322
  • 3
  • 53
  • 57
0

Just put file in the root directory of the project.

UmAnusorn
  • 10,420
  • 10
  • 72
  • 100
0
test
|___Binaries
|___Included
|___src
    |__test.cpp
    |__input.txt
|___Debug
|___Release

If this is your Eclipse C++ project structure, then to access contents of file input.txt in test.cpp you need to write

freopen("src/input.txt", "r", stdin);

"test" is the root dir

mouserat
  • 1,565
  • 13
  • 9