how to access a file in C:\

  • Thread starter Francesco Zavatarelli
  • Start date
R

Richard Bos

Francesco Zavatarelli said:
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:
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
 
M

Martin Ambuhl

Francesco said:
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.
 
B

Bernhard Holzmayer

Francesco said:
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
 
D

Default User

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,267
Latest member
WaylonCogb

Latest Threads

Top