FOPEN problem in Pure C

C and PASCAL (or any other high-level languages) in here please

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

Zamuel_a
Atari God
Atari God
Posts: 1234
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

FOPEN problem in Pure C

Postby Zamuel_a » Thu Feb 27, 2014 9:42 pm

In Pure C I tried to use the normal FOPEN command but can't get it to work with a full path. If I write the file I want to load as "file.dat" it's not a problem, but if I tries to include the full path "c:\folder\file.dat" it doesn't work. I also tried "c:/folder/file.dat" but it doesn't work either. Can't figure out what is wrong?
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe

joska
Hardware Guru
Hardware Guru
Posts: 4343
Joined: Tue Oct 30, 2007 2:55 pm
Location: Florø, Norway
Contact:

Re: FOPEN problem in Pure C

Postby joska » Thu Feb 27, 2014 10:43 pm

Stupid question, but you did write "c:\\folder\\file.dat", right?

Sent from my GT-I9506 using Tapatalk
Jo Even

VanillaMiNT - Firebee - Falcon060 - Milan060 - Falcon040 - MIST - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64

Zamuel_a
Atari God
Atari God
Posts: 1234
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: FOPEN problem in Pure C

Postby Zamuel_a » Thu Feb 27, 2014 11:26 pm

Stupid question, but you did write "c:\\folder\\file.dat", right?


No I didn't! I only had one \ on each location. Never needed two on PC, but maybe that's different here. Will try this! :)
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe

rpineau
Atari Super Hero
Atari Super Hero
Posts: 514
Joined: Wed Jun 29, 2011 6:39 am
Location: California / USA
Contact:

Re: FOPEN problem in Pure C

Postby rpineau » Fri Feb 28, 2014 4:59 am

That's weird
Does it just not work or not compile ?

it should be as simple as :

Code: Select all

FILE *fp;
fp=fopen("c:\folder\file.dat", "r");
...
Falcon + AB040 + Eclipse PCI + ATI Rage VGA card + NE2000 Ethernec + HxC Floppy Emulator
MegaSTE 4MB + CosmosEx / 1040 STF for hardware dev
http://www.rti-zone.org/atari.php

User avatar
mfro
Atari Super Hero
Atari Super Hero
Posts: 791
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: FOPEN problem in Pure C

Postby mfro » Fri Feb 28, 2014 5:56 am

rpineau wrote:That's weird
Does it just not work or not compile ?

it should be as simple as :

Code: Select all

FILE *fp;
fp=fopen("c:\folder\file.dat", "r");
...


Code: Select all

FILE *fp;
fp=fopen("c:\\folder\\file.dat", "r");
...


"Backslash" is the escape character in C strings (think about \n, \r. \t, ...). If you want a "real" backslash, you always have to write it twice.

Zamuel_a
Atari God
Atari God
Posts: 1234
Joined: Wed Dec 19, 2007 8:36 pm
Location: Sweden

Re: FOPEN problem in Pure C

Postby Zamuel_a » Fri Feb 28, 2014 6:39 am

Yes it worked! I have never needed to write it twice on PC in any C compiler, but instead there I always had to write a normal slash, /, but that didn't work in Pure C
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe

joska
Hardware Guru
Hardware Guru
Posts: 4343
Joined: Tue Oct 30, 2007 2:55 pm
Location: Florø, Norway
Contact:

Re: FOPEN problem in Pure C

Postby joska » Fri Feb 28, 2014 7:24 am

Forward slashes will work in MiNT, but not TOS.

Sent from my GT-I9506 using Tapatalk
Jo Even

VanillaMiNT - Firebee - Falcon060 - Milan060 - Falcon040 - MIST - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64

rpineau
Atari Super Hero
Atari Super Hero
Posts: 514
Joined: Wed Jun 29, 2011 6:39 am
Location: California / USA
Contact:

Re: FOPEN problem in Pure C

Postby rpineau » Fri Feb 28, 2014 7:32 am

mfro wrote:
rpineau wrote:That's weird
Does it just not work or not compile ?

it should be as simple as :

Code: Select all

FILE *fp;
fp=fopen("c:\folder\file.dat", "r");
...


Code: Select all

FILE *fp;
fp=fopen("c:\\folder\\file.dat", "r");
...


"Backslash" is the escape character in C strings (think about \n, \r. \t, ...). If you want a "real" backslash, you always have to write it twice.



Ooops.. totally forgot about that...I'm to used to code on Linux and Mac OS X nowdays. Sorry about that but now that I see it, it is obvious :)
Falcon + AB040 + Eclipse PCI + ATI Rage VGA card + NE2000 Ethernec + HxC Floppy Emulator
MegaSTE 4MB + CosmosEx / 1040 STF for hardware dev
http://www.rti-zone.org/atari.php

User avatar
mfro
Atari Super Hero
Atari Super Hero
Posts: 791
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: FOPEN problem in Pure C

Postby mfro » Fri Feb 28, 2014 7:36 am

Forward slashes were a valid character for filenames in early TOS versions (at least Fcreate() failed to reject them although TOS couldn't handle them through the desktop), so Atari never came round to make them illegal. Consequently, they cannot be used as path separator. MiNT changed the rules for good.


Social Media

     

Return to “C / PASCAL etc.”

Who is online

Users browsing this forum: No registered users and 2 guests