Re: [Dev-C++] More: Reading file with getc(fp)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Luigi S. <gi...@li...> - 2002-04-11 07:49:13
|
At 18:45 10/04/02 -0700, rchavez wrote:
>Hi,
>
>Thanks for the replies. I added a check for NULL file pointer and found
>that indeed it is NULL. That explains why the same code works in unix but
>not in Dev-C++. (In my defense I took the example directly from a book.)
>
>So 2 new questions:
>
>1. If the source file & the target file to be read are in the same
>directory I am using in Dev-C++, shouldn't
>
> fopen("filename","r") find the file? It doesn't seem to.
Uhm ... let me see if I understand the situation.
Say that I have a console application, named "cp.exe", which will duplicate
a file (the source code, "cp.c", is attached).
Now I have:
- the binary file in "c:\rch" (thus full path name of the file is
"c:\rch\cp.exe")
- the data file I wish to duplicate is "c:\rch\data.txt"
According to you, if I open a Dos box (I'm running Win98SE), switch my
current position such that the prompt says I'm in "c:\rch", and issue the
command:
cp data.txt a_copy.txt
I should expect some error to occur.
Well ... I did exactly what I described and no error occurred. :)
Now lets change situation.
I wish to run the console application "cp.exe" from within the Dev-C++ IDE
(i.e. I click the "run" button). It is possible, but I do not recommend it;
or better: I have only limited knowledge, so do not know hot to ensure that
Dev-C++ will run the application from the directory I want. IMHO, console
applications (by the way the sole kind of programs I am able to work out),
must be used from within a Dos console.
>2. Is
>
> fopen("C:\Dev-C++\Dir1\Dir2\filename","r") a valid explict path syntax in
>
>Windows 2000 ? (assuming Dir1 & Dir2 already exist)
I run Win98SE so can't say how things go on Win2000. However I think that
the path you have written, that is: "C:\Dev-C++\Dir1\Dir2\filename", is not
a valid one. Because of Dos using backslash ('\\') as directory separator,
your string appears as: "C:Dev-C++Dir1Dir2filename" (which is, highly
likely, a non existing file of the current directory on the unit "C"). The
right way to write your path is: "C:\\Dev-C++\\Dir1\\Dir2\\filename",
because this is the way to insert a backslash within a C string.
>There must be a better book for re-learning C than "A Book on C" or K&R!
This is something where I'm of little help, I've learned the few things I
know about C, from the well known K&R - 2nd edition. I remember the preface
telling that the book is not for beginners, but this should not be your
case since you are "re-learning".
>Regards,
>Rob.
--
Luigi
gi...@li... |