469,097 Members | 1,513 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,097 developers. It's quick & easy.

how to access a file in C:\

I downloaded a free c-compiler and I'm trying to access a file in a windows
directory c:\program files\... but I get an error when I run the code.
Probably my declaration char* NAME is wrong. Anybody can give a suggestion?
Thanks very much.
Fzavat
char* NAME_SMS = "c:\\Program Files\\Palm\\Tungst\\Backup\\SmsDB.PDB";

file_sms = fopen(NAME_SMS, "r");
if (file_sms == NULL) {
fprintf(stdout, "Error opening file.\n");
}

fclose(file_sms);

When I run the code I get the "Error opening file." message. If I try with
char* NAME_SMS = "c:\Program Files\Palm\Tungst\Backup\SmsDB.PDB"; I get a
compiler error: lexical: unknown escape sequence `\P'

Nov 14 '05 #1
23 2377
In 'comp.lang.c', "Francesco Zavatarelli" <fz****@tiscali.it> wrote:
char* NAME_SMS = "c:\\Program Files\\Palm\\Tungst\\Backup\\SmsDB.PDB";


Because of the presence of ' ' (SPACE) in the path name, your system probably
requires to wrap the string by double quotes. Also, it probably knows that
'/' is an alternative to '\\'

char* NAME_SMS = "\"c:/Program Files/Palm/Tungst/Backup/SmsDB.PDB\"";

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #2

"Francesco Zavatarelli" <fz****@tiscali.it> wrote in message
news:cc**********@ctb-nnrp2.saix.net...
I downloaded a free c-compiler and I'm trying to access a file in a windows directory c:\program files\... but I get an error when I run the code.
Probably my declaration char* NAME is wrong. Anybody can give a suggestion? Thanks very much.
Fzavat
char* NAME_SMS = "c:\\Program Files\\Palm\\Tungst\\Backup\\SmsDB.PDB";
try char *NAME_SMS="c:\Program Files\Palm\Tungst\Backup\SmsDB.PDB";


file_sms = fopen(NAME_SMS, "r");
if (file_sms == NULL) {
fprintf(stdout, "Error opening file.\n");
}

fclose(file_sms);
Be sure that file_sms is a FILE * .

When I run the code I get the "Error opening file." message. If I try with char* NAME_SMS = "c:\Program Files\Palm\Tungst\Backup\SmsDB.PDB"; I get a
compiler error: lexical: unknown escape sequence `\P'


If that don't work, what is the name of the compiler you are using?
Nov 14 '05 #3
In 'comp.lang.c', "Darksun4" <da*******@yahoo.gr> wrote:
char* NAME_SMS = "c:\\Program Files\\Palm\\Tungst\\Backup\\SmsDB.PDB";


try char *NAME_SMS="c:\Program Files\Palm\Tungst\Backup\SmsDB.PDB";


No. It's fully wrong.
char* NAME_SMS = "c:\Program Files\Palm\Tungst\Backup\SmsDB.PDB"; I get a
compiler error: lexical: unknown escape sequence `\P'


If that don't work, what is the name of the compiler you are using?


Any decent C compiler will refuse to compile such a code.

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #4
Darksun4 wrote:
"Francesco Zavatarelli" <fz****@tiscali.it> wrote in message
news:cc**********@ctb-nnrp2.saix.net...

When I run the code I get the "Error opening file." message. If I try


with
char* NAME_SMS = "c:\Program Files\Palm\Tungst\Backup\SmsDB.PDB"; I get a
compiler error: lexical: unknown escape sequence `\P'

If that don't work, what is the name of the compiler you are using?


If it *does* work, what is the name of the compiler *you* are using?
What meaning does it give to the escape sequences '\P', '\T', '\B', and
'\S'?

Nov 14 '05 #5
On Tue, 6 Jul 2004 11:06:36 +0200, Francesco Zavatarelli wrote:
[...]
char* NAME_SMS = "c:\\Program Files\\Palm\\Tungst\\Backup\\SmsDB.PDB";


[...]

Blanks in pathnames sometimes cause strange effects.
You might try encapsulating the pathname in " " like:

char* NAME_SMS = "\"c:\\Program
Files\\Palm\\Tungst\\Backup\\SmsDB.PDB\"";

(It's been quite a while since my last C programming activities, so
it's just an educated guess)
Nov 14 '05 #6
On Tue, 6 Jul 2004, Francesco Zavatarelli wrote:
I downloaded a free c-compiler and I'm trying to access a file in a windows
directory c:\program files\... but I get an error when I run the code.
Probably my declaration char* NAME is wrong. Anybody can give a suggestion?
Thanks very much.
Fzavat

char* NAME_SMS = "c:\\Program Files\\Palm\\Tungst\\Backup\\SmsDB.PDB";
As a few people have mentioned, the space in the path could be causing the
problem. It could also be a limitation of the compiler. Older MSDOS
compilers expect the name to be 8.3. When you have a path like "Program
Files" the compiler actually wants "PROGRA~1". This is a quirk of
MSDOS/Windows. You might want to check a newsgroup that is more familar
with your compiler (you didn't mention which one) or with your operating
system (Windows or MSDOS).
file_sms = fopen(NAME_SMS, "r");
if (file_sms == NULL) {
fprintf(stdout, "Error opening file.\n");
}

fclose(file_sms);

When I run the code I get the "Error opening file." message. If I try with
char* NAME_SMS = "c:\Program Files\Palm\Tungst\Backup\SmsDB.PDB"; I get a
compiler error: lexical: unknown escape sequence `\P'


The \P is definitely wrong. If you need a '\' in the path you need to put
'\\'.

--
Send e-mail to: darrell at cs dot toronto dot edu
Don't send e-mail to vi************@whitehouse.gov
Nov 14 '05 #7
Francesco Zavatarelli <fz****@tiscali.it> spoke thus:
char* NAME_SMS = "c:\\Program Files\\Palm\\Tungst\\Backup\\SmsDB.PDB";


const char *NAME_SMS;

String literals are not modifiable in the absence of certain compiler
extensions, so your declaration should reflect that.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #8
In 'comp.lang.c', Christopher Benson-Manica <at***@nospam.cyberspace.org>
wrote:
char* NAME_SMS = "c:\\Program Files\\Palm\\Tungst\\Backup\\SmsDB.PDB";


const char *NAME_SMS;

String literals are not modifiable in the absence of certain compiler
extensions, so your declaration should reflect that.


Good point.

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #9
Francesco Zavatarelli wrote:
I downloaded a free c-compiler and I'm trying to access a file in
a windows directory c:\program files\... but I get an error when I
run the code. Probably my declaration char* NAME is wrong. Anybody
can give a suggestion? Thanks very much.
Fzavat
char* NAME_SMS = "c:\\Program
Files\\Palm\\Tungst\\Backup\\SmsDB.PDB";

file_sms = fopen(NAME_SMS, "r");
if (file_sms == NULL) {
fprintf(stdout, "Error opening file.\n");
}

fclose(file_sms);

When I run the code I get the "Error opening file." message. If I
try with char* NAME_SMS = "c:\Program
Files\Palm\Tungst\Backup\SmsDB.PDB"; I get a compiler error:
lexical: unknown escape sequence `\P'


The reason why it fails, is obviously bc. of how escape sequences
are handled.
\\ evaluates to \ in the first stage of the lexical parsing,
then the sequence is searched for things like %s in a printf ...
This time it assumes that the backslash indicates that the following
token is meant as some special character / escape sequence.

If the resulting string should really contain backslashes as folder
separators, it might help to do an additional masking like
char* NAME_SMS = "c:\\\\Program...
That's not a joke.
In a certain chain of cascaded parsing stages in a real project,
I had to insert 8 backslashes in every place where you'd expect one
in the final output. So, don't wonder - take it easy - if it works.

Another possibility:
Some compilers understand forward slashes and will interpret them
correctly, so you'd try
char* NAME_SMS = "c:/Program.../SmsDB.PDB";

Then, to indicate the drive letter, try this one (used @ cygnus gcc)
char* NAME_SMS = "//c/Program...

// indicates the top level or root directory (like in UNIX) here.

The blank will certainly add additional problems as the other
posters indicated.
One chance is to merely escape it by one or two backslashes,
char* NAME_SMS = "//c/Program\ Files/... or
char* NAME_SMS = "//c/Program\\ Files/...

Another possibility is to add it using its character code (0x20).

Last not least, you could check if the compiler provides special
functions for this. Because it obviously doesn't feel comfortable
with the Windows-like path names, it will probably provide
translation methods for conversion between Windows-like path names
and maybe unix- or mac-like.

If you would like to check this, scan the include directory for
sub-directories with names like win, win32, sys, dos, local.

If nothing helps, reveal which compiler (and version) it is. Maybe
some of us know it.

Bernhard

Nov 14 '05 #10

On Tue, 6 Jul 2004, Bernhard Holzmayer wrote:

Francesco Zavatarelli wrote:

char* NAME_SMS = "c:\\Program Files\\Palm\\Tungst\\Backup\\SmsDB.PDB";
[...] The reason why it fails, is obviously bc. of how escape sequences
are handled.
Aha! Someone who uses "obviously" even more inappropriately than
myself! ;-) s/bc. of/not because of/
\\ evaluates to \ in the first stage of the lexical parsing,
Terminology is important in this newsgroup. \\ isn't an expression
and doesn't "evaluate" to anything. Nor does the first phase of
translation do anything special with backslashes. You might say
that "Doubled backslashes inside strings 'turn into' single backslashes
in the compiled program," with more elaboration depending on context
and relevancy.
then the sequence is searched for things like %s in a printf ...
This time it assumes that the backslash indicates that the following
token is meant as some special character / escape sequence.
Wrong, of course. You may be confusing C strings with Perl
quoting operators, which do all kinds of weird stuff. There's nothing
magic about the percent sign in C, and the only magic thing about
backslashes is the way doubled ones turn into single ones, only
once, during translation phase 5.
If the resulting string should really contain backslashes as folder
separators, it might help to do an additional masking like
char* NAME_SMS = "c:\\\\Program...
That's not a joke.
Then it's misguided, because taken literally it's very, very wrong.
In a certain chain of cascaded parsing stages in a real project,
I had to insert 8 backslashes in every place where you'd expect one
in the final output. So, don't wonder - take it easy - if it works.
This I find hard to believe. Do you still have the code anywhere,
or can you reconstruct it accurately from memory? I *have* had
occasion to use an octuple-backslash (line 61 of
http://www.contrib.andrew.cmu.edu/~a...ftware/quine.c
) but that was in a toy program done purely for hack value, not
for any practical purpose.

Another possibility:
Some compilers understand forward slashes and will interpret them
correctly, so you'd try
char* NAME_SMS = "c:/Program.../SmsDB.PDB";
This is not a compiler issue (all C compilers understand forward
slashes, since otherwise how could you divide two numbers?) but
rather an operating-system issue (most OSes understand slashes at
the system level, with some obvious exceptions and some not-so-
obvious non-exceptions, such as MS-DOS and Win32).
Then, to indicate the drive letter, try this one (used @ cygnus gcc)
char* NAME_SMS = "//c/Program...
This is a Unix convention and is highly unlikely to work on the
OP's Windows OS.
The blank will certainly add additional problems as the other
posters indicated.
One chance is to merely escape it by one or two backslashes,
char* NAME_SMS = "//c/Program\ Files/... or
char* NAME_SMS = "//c/Program\\ Files/...


One backslash ==> compiler diagnostic.
Two backslashes ==> might work, but I doubt it. (Untested.)

-Arthur

Nov 14 '05 #11
"Francesco Zavatarelli" <fz****@tiscali.it> wrote in message news:<cc**********@ctb-nnrp2.saix.net>...
I downloaded a free c-compiler and I'm trying to access a file in a windows
directory c:\program files\... but I get an error when I run the code.
Probably my declaration char* NAME is wrong. Anybody can give a suggestion?
Thanks very much.
Fzavat
char* NAME_SMS = "c:\\Program Files\\Palm\\Tungst\\Backup\\SmsDB.PDB";

file_sms = fopen(NAME_SMS, "r");
if (file_sms == NULL) {
fprintf(stdout, "Error opening file.\n");
}

fclose(file_sms);

When I run the code I get the "Error opening file." message. If I try with
char* NAME_SMS = "c:\Program Files\Palm\Tungst\Backup\SmsDB.PDB"; I get a
compiler error: lexical: unknown escape sequence `\P'


You probably want to be asking in a windows specific group, as
your issue is quite platform specific.

[OT stab at answering, your mileage may vary]
There are two things you might try:
1) Substitute Progra~1 for "Program files". Not perfect, but it will usually
work unless there is another directory at the root of the C drive starting
with progra..., in which case it is not a good solution. If you to use
the backslash file name scheme you may need to resort to this.

2) Best solution: use forward slashes in your path. It'll just work then.
The following works just fine for me...

#include <stdio.h>

int main()
{
const char* NAME_SMS = "c:/Program Files/testing";

FILE *file_sms = fopen(NAME_SMS, "r");
if (file_sms == NULL) {
fprintf(stdout, "Error opening file '%s'.\n", NAME_SMS);
}
else {
fclose(file_sms);
}

return 0;
}
[OT]

-David
Nov 14 '05 #12
Francesco Zavatarelli wrote:
[...]
char* NAME_SMS = "c:\\Program Files\\Palm\\Tungst\\Backup\\SmsDB.PDB";

file_sms = fopen(NAME_SMS, "r");
if (file_sms == NULL) {
fprintf(stdout, "Error opening file.\n");
}

fclose(file_sms);

When I run the code I get the "Error opening file." message. If I try with
char* NAME_SMS = "c:\Program Files\Palm\Tungst\Backup\SmsDB.PDB"; I get a
compiler error: lexical: unknown escape sequence `\P'


With all of these replies concentrating on your non-existent "problem"
with the backslashes, no one has pointed out the obvious:

Use perror() to determine why it failed.

Perhaps you have a typo in the name, and the filename you are using doesn't
exist? Perhaps the file is open in "exclusive mode" by another program, and
you cannot open it because of this? Perhaps you don't have permissions to
access this file?

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody at spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Nov 14 '05 #13
Emmanuel Delahaye wrote:

In 'comp.lang.c', "Francesco Zavatarelli" <fz****@tiscali.it> wrote:
char* NAME_SMS = "c:\\Program Files\\Palm\\Tungst\\Backup\\SmsDB.PDB";


Because of the presence of ' ' (SPACE) in the path name, your system probably
requires to wrap the string by double quotes. Also, it probably knows that
'/' is an alternative to '\\'

char* NAME_SMS = "\"c:/Program Files/Palm/Tungst/Backup/SmsDB.PDB\"";


Not unless the filename actually contains those quotes. There is no
problem with spaces in the filename, as you are not passing it to a
program which may be interpreting the spaces as a command-line seperator.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody at spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Nov 14 '05 #14
Bernhard Holzmayer wrote:
[...]
char* NAME_SMS = "c:\\Program Files\\Palm\\Tungst\\Backup\\SmsDB.PDB";

file_sms = fopen(NAME_SMS, "r");
if (file_sms == NULL) {
fprintf(stdout, "Error opening file.\n");
}

fclose(file_sms);

When I run the code I get the "Error opening file." message. If I
try with char* NAME_SMS = "c:\Program
Files\Palm\Tungst\Backup\SmsDB.PDB"; I get a compiler error:
lexical: unknown escape sequence `\P'


The reason why it fails, is obviously bc. of how escape sequences
are handled.
\\ evaluates to \ in the first stage of the lexical parsing,
then the sequence is searched for things like %s in a printf ...
This time it assumes that the backslash indicates that the following
token is meant as some special character / escape sequence.

If the resulting string should really contain backslashes as folder
separators, it might help to do an additional masking like
char* NAME_SMS = "c:\\\\Program...
That's not a joke.


Absolutely wrong! That will result in "c:\\Program ..." being passed
as the filename, and you absolutely do not want to be passing double
backslashes, as this will confuse some versions of Windows to no end.
(It will look for a system called "Program Files", just as if you were
to try the Windows-ish "\\server\sharename" format.)

This is not printf! This is fopen!

Since this is (apparently) Windows, you want to pass the filename:

c:\Program Files\Palm\...

To get the single-backslash in the string, you use double-backslashes
in the source:

"c:\\Program Files\\Palm\\..."

Which is exactly what he has.

On a side note, DOS and Windows have always taken forwardslashes in
path names, so you could just as easily use:

"c:/Program Files/Palm/..."

However, this will have no effect on whatever the real problem is here.

[...]

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody at spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Nov 14 '05 #15
Kenneth Brody wrote:
Emmanuel Delahaye wrote:
In 'comp.lang.c', "Francesco Zavatarelli" <fz****@tiscali.it> wrote:

char* NAME_SMS = "c:\\Program Files\\Palm\\Tungst\\Backup\\SmsDB.PDB";


Because of the presence of ' ' (SPACE) in the path name, your system probably
requires to wrap the string by double quotes. Also, it probably knows that
'/' is an alternative to '\\'

char* NAME_SMS = "\"c:/Program Files/Palm/Tungst/Backup/SmsDB.PDB\"";

Not unless the filename actually contains those quotes. There is no
problem with spaces in the filename, as you are not passing it to a
program which may be interpreting the spaces as a command-line seperator.


You are probably mistaken. Most command line parsers treat 'space'
as a separator. Micro$oft does. The explicit quotes combine the
enclosed characters into one argument.
--
Joe Wright mailto:jo********@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 14 '05 #16
Joe Wright <jo********@comcast.net> wrote:
Kenneth Brody wrote:
Emmanuel Delahaye wrote:
In 'comp.lang.c', "Francesco Zavatarelli" <fz****@tiscali.it> wrote:

char* NAME_SMS = "c:\\Program Files\\Palm\\Tungst\\Backup\\SmsDB.PDB";

Because of the presence of ' ' (SPACE) in the path name, your system probably
requires to wrap the string by double quotes.


Not unless the filename actually contains those quotes. There is no
problem with spaces in the filename, as you are not passing it to a
program which may be interpreting the spaces as a command-line seperator.


You are probably mistaken. Most command line parsers treat 'space'
as a separator. Micro$oft does.


Erm... yes. But I think Kenneth's point was that command line parsers
are immaterial, since this string does _not_ get passed to a command
line parser, but to fopen(). fopen() _should_ expect a single file name,
not a command line.

Richard
Nov 14 '05 #17
Sorry, I got something wrong:
I thought compiler wound complain \\P with the last lexical error
about escape sequence \P

Therefore I assumed that the parser might be broken or handling
stuff strangely.

With correct reading of the original post, I agree to your
correction - and apologize for my inadequate post.

Bernhard
Nov 14 '05 #18
Francesco Zavatarelli wrote:

char* NAME_SMS = "c:\\Program Files\\Palm\\Tungst\\Backup\\SmsDB.PDB";
file_sms = fopen(NAME_SMS, "r");
if (file_sms == NULL) {
fprintf(stdout, "Error opening file.\n");
}

fclose(file_sms);


I checked with gnu (cygnus) on Win2000 Prof.,

writing path name like
const char* NAME_SMS =
"//C/Program Files/Palm/Tungst/Backup/SmsDB.PDB";

works. Give it a try.

Bernhard
Nov 14 '05 #19
Back after a few days...

1)the c compiler I'm using is "Miracle C" see http://www.c-compiler.com
anybody knows it? Anybody can give me an advice of a low cost c compiler?

2)and I am having a lot of troubles with the code. It seems it is not
related to the ' ' inside the string.

In fact I'm using the following code now (with the italian version of the
path which has Programmi instead of Program Files). Must be a BIG errore tat
I cannot see at all...

---start of code:
#include <stdio.h>
FILE* file_sms;

char* NAME_SMS = "C:\Programmi\Palm\Tungst\Backup\SmsDB.PDB";

main()
{
file_sms = fopen(NAME_SMS, "r");
if (file_sms == NULL) { fprintf(stdout, "Error opening sms file
%s\n",NAME_SMS); }
fclose(file_sms);
....etc
---endof code:

if I use char* NAME_SMS = "C:\Programmi\Palm\Tungst\Backup\SmsDB.PDB";
I get the error:
main.c: line 21: lexical: unknown escape sequence `\P'

'char* NAME_SMS = "C:\Programmi\Palm\Tungst\Backup\SmsDB.PDB"'

aborting compile

If I use char* NAME_SMS = "C:/Programmi/Palm/Tungst/Backup/SmsDB.PDB";
compiling ok but I ger an error when I run the program: Error opening sms
file C:/Programmi/Palm/Tungst/Backup/SmsDB.PDB

If I use char* NAME_SMS = "\"c:/Programmi/Palm/Tungst/Backup/SmsDB.PDB\"";
compiling is ok but still I get the error: Error opening sms file
"c:/Programmi/Palm/Tungst/Backup/SmsDB.PDB"
thanks for any suggestion.
FZ
"Chiron Paixos" <CH**********@spammotel.com> ha scritto nel messaggio
news:9g********************************@4ax.com...
On Tue, 6 Jul 2004 11:06:36 +0200, Francesco Zavatarelli wrote:
[...]
char* NAME_SMS = "c:\\Program Files\\Palm\\Tungst\\Backup\\SmsDB.PDB";


[...]

Blanks in pathnames sometimes cause strange effects.
You might try encapsulating the pathname in " " like:

char* NAME_SMS = "\"c:\\Program
Files\\Palm\\Tungst\\Backup\\SmsDB.PDB\"";

(It's been quite a while since my last C programming activities, so
it's just an educated guess)

Nov 14 '05 #20
"Francesco Zavatarelli" <fz****@tiscali.it> wrote:
1)the c compiler I'm using is "Miracle C" see http://www.c-compiler.com
anybody knows it? Anybody can give me an advice of a low cost c compiler?
I'm currently using Dev-C++ (which also does C), and quite satisfied:
<http://www.bloodshed.net/>
2)and I am having a lot of troubles with the code. It seems it is not
related to the ' ' inside the string.
No, it's partly related to the \s inside the string.
char* NAME_SMS = "C:\Programmi\Palm\Tungst\Backup\SmsDB.PDB";
Imprimis, this isn't right in any case. You had it right the first time:
the \ is the escape character, and if you want a literal \ in a string,
it must be escaped itself.

Secundis, maybe Miracle C can't handle non-DOS path names. Try replacing
"Programmi" with the short name of that directory, probably "progra~1".
file_sms = fopen(NAME_SMS, "r");
Oh, btw: a .PDB-file is probably a binary file (it's a kind of database,
isn't it?, so you want to open it "rb". Not that this should cause
fopen() to fail, but once you do manage to open it, using "r" could
cause some surprises when you read from it.
if I use char* NAME_SMS = "C:\Programmi\Palm\Tungst\Backup\SmsDB.PDB";
I get the error:
main.c: line 21: lexical: unknown escape sequence `\P'
Well, yes. Why did you change this, anyway?
If I use char* NAME_SMS = "C:/Programmi/Palm/Tungst/Backup/SmsDB.PDB";
compiling ok but I ger an error when I run the program: Error opening sms
file C:/Programmi/Palm/Tungst/Backup/SmsDB.PDB
This may be to do with the MS-DOS filename issue; if not, try opening
another file, if possible without a path name, and then one in the root
directory, just to see if that works.
If I use char* NAME_SMS = "\"c:/Programmi/Palm/Tungst/Backup/SmsDB.PDB\"";
compiling is ok but still I get the error: Error opening sms file
"c:/Programmi/Palm/Tungst/Backup/SmsDB.PDB"


That's expected. fopen() sees the entire string as the path name, extra
quote marks and all.

Richard
Nov 14 '05 #21
Francesco Zavatarelli wrote:
2)and I am having a lot of troubles with the code. It seems it is not
related to the ' ' inside the string.
It's related to your use of unrecognized escape sequences, fully covered
in any elementary C text as well as in the FAQ.

Change char* NAME_SMS = "C:\Programmi\Palm\Tungst\Backup\SmsDB.PDB";

To
char* NAME_SMS = "C:/Programmi/Palm/Tungst/Backup/SmsDB.PDB";

None of the escape sequences '\P', '\T', \B', and '\S' is wanted here.
Nov 14 '05 #22
Francesco Zavatarelli wrote:
Must be a BIG errore tat
I cannot see at all...


Let's assume a big error:
are you sure that the file exists?
If not, evrything is ok. Program works correct.

There was another idea, which Kenneth provided:
....
Use perror() to determine why it failed.
....
Did you try this.
It should provide an exploitable error message.

What does it say?

Bernhard
Nov 14 '05 #23
Francesco Zavatarelli wrote:
If I use char* NAME_SMS = "C:/Programmi/Palm/Tungst/Backup/SmsDB.PDB";
compiling ok but I ger an error when I run the program: Error opening sms
file C:/Programmi/Palm/Tungst/Backup/SmsDB.PDB


You need to learn to troubleshoot. Start with a very simple file to
open, one with a DOS name in the local directory. Expand to include
paths, spaces in the pathname, non-DOS name, etc. You should be able to
figure out where your implementation is falling down.


Brian Rodenborn
Nov 14 '05 #24

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by *no spam* | last post: by
4 posts views Thread by bbdobuddy | last post: by
70 posts views Thread by lgbjr | last post: by
49 posts views Thread by Mell via AccessMonster.com | last post: by
17 posts views Thread by Mell via AccessMonster.com | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.