473,473 Members | 1,692 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

fopen() with full path affecting subsequent fopen calls

I made a program that accepts as parameters an input file name that
we'll call file1, and an output file name that we'll call file2, and
opens on its own a configuration file called file3. My program works
correctly when calling it like this : ./program file1 file2, and also
with full paths, like this : ./program c:\dir\file1 c:\dir\file2

However, a most puzzling phenomenon occurs when I use the full path
only for the first file, like this : ./program c:\dir\file1 file2.
Normally I would expect file2 to be written in the same place as it
did when I didn't use the full path for file1. Only that's not what
happens. File2 gets successfully written to, as well as file3 (which
my program loads data from and saves data into), only not where I
expect, and actually, I don't have a single clue where they can be.
They're surely getting written to a valid place because the program
operates normally and file3, the one from the mysterious location,
gets read from normally.

So here's my problem stated in a more concise manner : if I call
fopen() using a full path, it affects subsequent fopen() calls in that
if they don't call absolute paths they will try to reach the files in
an unknown location, which is definitely not what I want.

I'd really like to understand how one fopen() call can affect all
others, although they are completely unrelated, and how I can make
sure this doesn't happen. Oh and I made sure this wasn't a backslash
issue by replacing backslashes with forward slashes in my full paths.

Thanks in advance
Jun 27 '08 #1
4 2817
On Apr 28, 3:14 pm, Michel Rouzic <Michel0...@yahoo.frwrote:
I made a program that accepts as parameters an input file name that
we'll call file1, and an output file name that we'll call file2, and
opens on its own a configuration file called file3. My program works
correctly when calling it like this : ./program file1 file2, and also
with full paths, like this : ./program c:\dir\file1 c:\dir\file2

However, a most puzzling phenomenon occurs when I use the full path
only for the first file, like this : ./program c:\dir\file1 file2.
Normally I would expect file2 to be written in the same place as it
did when I didn't use the full path for file1. Only that's not what
happens. File2 gets successfully written to, as well as file3 (which
my program loads data from and saves data into), only not where I
expect, and actually, I don't have a single clue where they can be.
They're surely getting written to a valid place because the program
operates normally and file3, the one from the mysterious location,
gets read from normally.

So here's my problem stated in a more concise manner : if I call
fopen() using a full path, it affects subsequent fopen() calls in that
if they don't call absolute paths they will try to reach the files in
an unknown location, which is definitely not what I want.
Of course it does not. We can't be 100% sure of what actually happends
without seeing your code.
Try to isolate the problem in the least lines possible before you post
it.
Jun 27 '08 #2

<vi******@gmail.comwrote in message
news:62**********************************@j22g2000 hsf.googlegroups.com...
On Apr 28, 3:14 pm, Michel Rouzic <Michel0...@yahoo.frwrote:
I made a program that accepts as parameters an input file name that
we'll call file1, and an output file name that we'll call file2, and
opens on its own a configuration file called file3. My program works
correctly when calling it like this : ./program file1 file2, and also
with full paths, like this : ./program c:\dir\file1 c:\dir\file2

However, a most puzzling phenomenon occurs when I use the full path
only for the first file, like this : ./program c:\dir\file1 file2.
Normally I would expect file2 to be written in the same place as it
did when I didn't use the full path for file1. Only that's not what
happens. File2 gets successfully written to, as well as file3 (which
my program loads data from and saves data into), only not where I
expect, and actually, I don't have a single clue where they can be.
They're surely getting written to a valid place because the program
operates normally and file3, the one from the mysterious location,
gets read from normally.

So here's my problem stated in a more concise manner : if I call
fopen() using a full path, it affects subsequent fopen() calls in that
if they don't call absolute paths they will try to reach the files in
an unknown location, which is definitely not what I want.
Of course it does not. We can't be 100% sure of what actually happends
without seeing your code.
Try to isolate the problem in the least lines possible before you post
it.
It's very likely a "current working directory" problem of some sort,
and of course, not a part of the "C" standard, like all directory issues.
Despite the egregious off-topic nature of the post, he should search
through the documentation for his compiler for functions that change
the "current working directory", and then evaluate carefully what
that directory would be at each fopen() call.

---
William Ernest Reid

Jun 27 '08 #3
In article <dH*********************@bgtnsc05-news.ops.worldnet.att.net>,
Bill Reid <ho********@happyhealthy.netwrote:
>It's very likely a "current working directory" problem of some sort,
and of course, not a part of the "C" standard, like all directory issues.
Despite the egregious off-topic nature of the post, he should search
through the documentation for his compiler for functions that change
the "current working directory", and then evaluate carefully what
that directory would be at each fopen() call.
It might be useful to print out the current directory before each call
to fopen(), to see if it's changing. I take it from the filenames
that it's a Windows system, but quite likely the Posix getcwd()
function will be available.

-- Richard
--
:wq
Jun 27 '08 #4


Bill Reid wrote:
It's very likely a "current working directory" problem of some sort,
and of course, not a part of the "C" standard, like all directory issues.
Despite the egregious off-topic nature of the post, he should search
through the documentation for his compiler for functions that change
the "current working directory", and then evaluate carefully what
that directory would be at each fopen() call.
My bad, seems like I mis-reported my problem. It seems to only happen
when I drag and drop file1 on the program. I used your advice and did
a getcwd() and as it turns out when and only when I drag and drop
file1 on the program, the current working directory changes to c:
\windows\system32, and that happens even before any fopen() call.

My apologies, this is decidedly a platform specific problem.
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: comp.lang.php | last post by:
Using Linux/PHP 4.3.2 CLI: $fileID = fopen('myfile.txt', 'r'); // WORKS JUST FINE Using Linux/PHP 4.3.8 CLI: $fileID = fopen('myfile.txt'); // THROWS WARNING 'no such file or directory...
4
by: Tank | last post by:
ld.so.1: internal: malloc failed I'm getting the above on a simple fopen() in a production program. I know that fopen calls malloc, but what would cause this and how do I fix it? Have I hit...
5
by: Arturo Ordaz | last post by:
Has anyone run into documentation that describes how fopen(log_file, "a") behaves when it is potentialy used (called/referenced) 1000's of times an hour on a single resource file? I am trying to...
15
by: tschi-p | last post by:
maybe my question is quite simple, but although searching like wild I cannot find a solution. I just want to append to a file, let's say to "c:\my folder\filename1.txt". Normally with...
3
by: Patrice | last post by:
Hi, I would to call fopen function several time in my application. This application permits to read files which path is registered in a configuration file. For exemple: File 1 = toto.txt File 2...
19
by: lihua | last post by:
Hi, Group! I got one question here: We all know that fclose() must be called after file operations to avoid unexpected errors.But there are really cases when you forget to do that!Just like...
25
by: subramanian100in | last post by:
Consider the following program: #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv) { if (argc != 2) { printf("Usage: <program-name<text-file>\n");
1
by: carpediem | last post by:
Hi, I am developing an application in Borland C++ 6, one of my functions opens a file and loads it into the memory. I have never had problems with fopen, but this bug is really weird, fopen...
1
by: stillnight | last post by:
My web host has disabled fopen and now uses curl. I am a newbie to php so I am at a complete loss. I am trying to change the code in sendcard at sendcard.org to use curl. The beginning login will...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.