473,766 Members | 2,172 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:\\Progra m Files\\Palm\\Tu ngst\\Backup\\S msDB.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\Tung st\Backup\SmsDB .PDB"; I get a
compiler error: lexical: unknown escape sequence `\P'

Nov 14 '05 #1
23 2655
In 'comp.lang.c', "Francesco Zavatarelli" <fz****@tiscali .it> wrote:
char* NAME_SMS = "c:\\Progra m Files\\Palm\\Tu ngst\\Backup\\S msDB.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:\\Progra m Files\\Palm\\Tu ngst\\Backup\\S msDB.PDB";
try char *NAME_SMS="c:\P rogram Files\Palm\Tung st\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\Tung st\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*******@yaho o.gr> wrote:
char* NAME_SMS = "c:\\Progra m Files\\Palm\\Tu ngst\\Backup\\S msDB.PDB";


try char *NAME_SMS="c:\P rogram Files\Palm\Tung st\Backup\SmsDB .PDB";


No. It's fully wrong.
char* NAME_SMS = "c:\Program Files\Palm\Tung st\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\Tung st\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:\\Progra m Files\\Palm\\Tu ngst\\Backup\\S msDB.PDB";


[...]

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

char* NAME_SMS = "\"c:\\Prog ram
Files\\Palm\\Tu ngst\\Backup\\S msDB.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:\\Progra m Files\\Palm\\Tu ngst\\Backup\\S msDB.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\Tung st\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:\\Progra m Files\\Palm\\Tu ngst\\Backup\\S msDB.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)cybers pace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #8
In 'comp.lang.c', Christopher Benson-Manica <at***@nospam.c yberspace.org>
wrote:
char* NAME_SMS = "c:\\Progra m Files\\Palm\\Tu ngst\\Backup\\S msDB.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:\\Progra m
Files\\Palm\\Tu ngst\\Backup\\S msDB.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\Tung st\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

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

Similar topics

3
6121
by: *no spam* | last post by:
I want to move my Access 2K database into MSDE. The Access Upsizing Wizard crashes (a known bug wi A2K), so I'm using the following suggested method: Access --> New --> Project (Existing Database) This asks for the name of the .adp file to create and then launches into the Data Link Properties dialog box (so far so good) I select my MSDE server from the drop-down, enter the sa account & passwd, attach a database file and try to...
2
7873
by: bbxrider | last post by:
is there no other way to use access(.mdb) across the internet?? (than vpn or worse yet terminal services) i'm trying to write to a mdb on my organization win2k server from my webhost redhat webserver with perl. then i have an 'inside' application that will connect to the same db with a vb program across the lan, this part is no problem vpn is theoretically possible but not realistic in my situation is it much simpler if the sql server...
10
6045
by: MHenry | last post by:
Hi, We were going merrily along for 6 years using this database to record all client checks that came into our office, including information about what the checks were for. Suddenly, network computers cannot access the database. The message is...
8
3151
by: John Baker | last post by:
Hi: I am URGENTLY in need of some book or web site OR tool that will help me integrate a relatively simple access application into a web page or pages. This is a time recording system (by project), and I would be more than wiling to pull the updated database down from the Host using FTP on a monthly basis. Its just that I need to understand how to set it up on the web site itself. The Host supports SQL. Any direction you can give would...
0
3292
by: bettervssremoting | last post by:
To view the full article, please visit http://www.BetterVssRemoting.com Better VSS Remote Access Tool including SourceOffSite, SourceAnyWhere and VSS Remoting This article makes a detailed comparison among SourceAnyWhere, SourceOffSite, VSS Remoting and possible others.
4
12283
by: bbdobuddy | last post by:
Hi, How do I open a Microsoft Access 2003 form from Visual Basic.net Thanks in advance bbdobuddy
70
3388
by: lgbjr | last post by:
Hello All, I've been developing a VB.NET app that requires the use of a DB. Up to now, I've been using Access. It's a bit slow, but everything works. I'm at a point now where I need to decide if I should stay with Access or move the DB to SQL. I'm trying to come up with a list of Pros/Cons for such a move. My list is a bit lopsided, as I have very little experience with SQL and quite a bit with Access. PROS for moving to SQL:
8
3137
by: carriolan | last post by:
Hi I have an MS Access based application almost ready for distribution to the public and I find that even though I have compiled it into an MDE file, tables and queries can still be be imported if accessed by another MS Access database. How can I stop this please? Regards Carriolan
49
3235
by: Mell via AccessMonster.com | last post by:
I created databases on Access 2003 and I want to deploy them to users. My code was also done using 2003. If they have Ms Access 2000 or higher, will they be able to use these dbs with all code, etc? Please explain -- Message posted via http://www.accessmonster.com
17
4416
by: Mell via AccessMonster.com | last post by:
Is there a way to find out where an application was created from? i.e. - work or home i.e. - if application sits on a (work) server/network, the IT people know the application is sitting there, but is there a way they can find out if that application was put there from a CD or email or created at work? Hint: It's not on a client/server database, just native jet database mdb created on Access 2003 (default 2000)...
0
10168
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10009
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9838
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8835
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7381
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3929
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 we have to send another system
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.