I have a program in c. Input of this program is the address of a file. This program gets the complete address of input file like d:\bin\files\examples\data\file.txt. How can I correct the program that gets input in form of data\file.txt ? and the d:\bin\files\examples\ add itself.
Asked
Active
Viewed 60 times
0
-
If you dont want to enter your full path you can enter a path relative to your executable. – Simon Karlsson Mar 03 '14 at 12:13
-
http://stackoverflow.com/questions/933850/how-to-find-the-location-of-the-executable-in-c – Ferenc Deak Mar 03 '14 at 12:13
-
What do you mean by "add itself"? – doctorlove Mar 03 '14 at 12:14
-
How can I enter a path relative to executable? – Mar 03 '14 at 12:15
-
`..` means up a directory... – doctorlove Mar 03 '14 at 12:22
-
1show us examples of running your command and explain better what's wrong and how do you want this program to behave. – zoska Mar 03 '14 at 13:09
2 Answers
0
Just do it. while the c program is below the directory d:/bin/files/examples and compile ,then execute it with the direct argument data/file.txt.

xuefu
- 61
- 7
0
Take a look at getcwd function. You will get current working directory path. Apply your logic what part to add. Use sprintf to complete the path.

gangadhars
- 2,584
- 7
- 41
- 68