![]() |
| | #1 |
| Registered User Join Date: Jan 2006
Posts: 32
| fopen help. I am having a problem with fopen. I have searched the forum but with no luck. i am trying to open a binary file using fopen. I am using Borland C++ 3.1 and it cannot open the file. fopen gives a NULL pointer. When opening the same program in Turbo C++ for Windows it seems to work correctly. the file is stored in the follow location J:\dsaaIII\ass1\Program 3\DATABASE.BIN This is my code Code: char fname[]="J:\\dsaaIII\\ass1\\Program 3\\DATABASE.BIN";
FILE * ptrFile;
ptrFile=fopen(fname, "rt");
if(ptrFile==NULL){
printf("\n Error Opening Database File!\n\n Please Press Any Key To Continue >");
getch();
clrscr();
return 0;
}
fread( lastRecordID, sizeof(int), 1, ptrFile );
fclose(ptrFile);
Thanks in advance. Chris |
| chriscolden is offline | |
| | #3 |
| Registered User Join Date: Oct 2001
Posts: 2,936
| >J:\\dsaaIII\\ass1\\Program 3\\DATABASE.BIN Borland C++ 3.1 probably doesn't support directories/filenames longer than eight characters. Under DOS, "Program 3" would probably equate to a name like "Progra~1".
__________________ http://www.freechess.org |
| swoopy is offline | |
| | #4 |
| Frequently Quite Prolix Join Date: Apr 2005 Location: Canada
Posts: 7,698
| Turbo C++ might only support 8.3 filenames. Or else you might need quotes: Code: char fname[]="\"J:\\dsaaIII\\ass1\\Program 3\\DATABASE.BIN\"";
__________________ dwk Seek and ye shall find. quaere et invenies. "Simplicity does not precede complexity, but follows it." -- Alan Perlis "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra "The only real mistake is the one from which we learn nothing." -- John Powell Other boards: DaniWeb, TPS Unofficial Wiki FAQ: cpwiki.sf.net My website: http://dwks.theprogrammingsite.com/ Projects: codeform, xuni, atlantis, nort, etc. |
| dwks is offline | |
| | #5 | |
| Frequently Quite Prolix Join Date: Apr 2005 Location: Canada
Posts: 7,698
| Quote:
Code: C>J: C>cd \dsaaIII\ass1\ C>dir "Program 3"
__________________ dwk Seek and ye shall find. quaere et invenies. "Simplicity does not precede complexity, but follows it." -- Alan Perlis "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra "The only real mistake is the one from which we learn nothing." -- John Powell Other boards: DaniWeb, TPS Unofficial Wiki FAQ: cpwiki.sf.net My website: http://dwks.theprogrammingsite.com/ Projects: codeform, xuni, atlantis, nort, etc. | |
| dwks is offline | |
| | #6 |
| Registered User Join Date: Oct 2001
Posts: 2,936
| >Windows XP will give it a random 8.3 name. Are you sure? Because under the Windows XP version I'm using it doesn't appear to be random.
__________________ http://www.freechess.org |
| swoopy is offline | |
| | #7 |
| Registered User Join Date: Jan 2006
Posts: 32
| Hey, thanks for your help so far. I got... Directory of J:\dsaaIII\ass\Program 3 .... does this mean its ok?? Chris |
| chriscolden is offline | |
| | #8 |
| Frequently Quite Prolix Join Date: Apr 2005 Location: Canada
Posts: 7,698
| Oops, my mistake. Use Code: C>dir program* Code: qwerty <DIR> 11-11-11 12.00p Program 3
__________________ dwk Seek and ye shall find. quaere et invenies. "Simplicity does not precede complexity, but follows it." -- Alan Perlis "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra "The only real mistake is the one from which we learn nothing." -- John Powell Other boards: DaniWeb, TPS Unofficial Wiki FAQ: cpwiki.sf.net My website: http://dwks.theprogrammingsite.com/ Projects: codeform, xuni, atlantis, nort, etc. |
| dwks is offline | |
| | #9 | ||
| Frequently Quite Prolix Join Date: Apr 2005 Location: Canada
Posts: 7,698
| Quote:
Quote:
__________________ dwk Seek and ye shall find. quaere et invenies. "Simplicity does not precede complexity, but follows it." -- Alan Perlis "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra "The only real mistake is the one from which we learn nothing." -- John Powell Other boards: DaniWeb, TPS Unofficial Wiki FAQ: cpwiki.sf.net My website: http://dwks.theprogrammingsite.com/ Projects: codeform, xuni, atlantis, nort, etc. | ||
| dwks is offline | |
| | #10 |
| Registered User Join Date: Jan 2006
Posts: 32
| i have just tried that but cannot seem to make it display anythin random. Chris |
| chriscolden is offline | |
| | #11 |
| Frequently Quite Prolix Join Date: Apr 2005 Location: Canada
Posts: 7,698
| Can you post the output of the dir command? Unless the double-quote thing solved the problem, in which case don't bother.
__________________ dwk Seek and ye shall find. quaere et invenies. "Simplicity does not precede complexity, but follows it." -- Alan Perlis "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra "The only real mistake is the one from which we learn nothing." -- John Powell Other boards: DaniWeb, TPS Unofficial Wiki FAQ: cpwiki.sf.net My website: http://dwks.theprogrammingsite.com/ Projects: codeform, xuni, atlantis, nort, etc. |
| dwks is offline | |
| | #12 |
| Registered User Join Date: Jan 2006
Posts: 32
| Thanks for all your help. I have got it working now. It was because i was typing the wrong thing into dos. I have got the shorter name for the folder Program 3 and it seems to work ok now. Thanks again Chris |
| chriscolden is offline | |
| | #13 |
| Registered User Join Date: Oct 2001
Posts: 2,936
| >I thought it would be like that, too, but it seems random to me. Well I wasn't using the dir command, but instead was using a 16-bit windows program, and it wasn't coming up random. Tomorrow I'll try the dir command and see what it displays.
__________________ http://www.freechess.org |
| swoopy is offline | |
| | #14 |
| Registered User Join Date: Oct 2001
Posts: 2,936
| Ok, I tried the dir command on my XP machine, and the 8.3 filenames are not random. Maybe someone else can try it on XP and see what they get.
__________________ http://www.freechess.org |
| swoopy is offline | |
| | #15 |
| Frequently Quite Prolix Join Date: Apr 2005 Location: Canada
Posts: 7,698
| I would expect it to be non-random. But my link seems to suggest otherwise.
__________________ dwk Seek and ye shall find. quaere et invenies. "Simplicity does not precede complexity, but follows it." -- Alan Perlis "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra "The only real mistake is the one from which we learn nothing." -- John Powell Other boards: DaniWeb, TPS Unofficial Wiki FAQ: cpwiki.sf.net My website: http://dwks.theprogrammingsite.com/ Projects: codeform, xuni, atlantis, nort, etc. |
| dwks is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| help with stat() and fopen() | movl0x1 | C Programming | 6 | 07-25-2007 05:28 AM |
| fopen and encoding of "*filename" argument. | techi_talk | C Programming | 4 | 05-16-2006 11:36 PM |
| problem with fopen command | emon | C Programming | 2 | 03-12-2004 12:11 AM |
| fopen() and open() | Encrypted | C Programming | 8 | 02-09-2003 04:57 PM |
| fopen vs open | rotis23 | Linux Programming | 5 | 12-10-2002 02:30 PM |