Article View: pl.comp.lang.c
Article #310698rename function problem . . . 'permission denied'
From: John Cooney
Date: Mon, 14 Jun 1999 20:30
Date: Mon, 14 Jun 1999 20:30
127 lines
4901 bytes
4901 bytes
Hi!
I'm a student learning C requiring a few helpful suggestions/solutions . . .
Below is a small excerpt from a program I'm messing around with. It's
basically a simple database, to be run in DOS.
The excerpt shown is within a case option, within a while loop that
returns user to start of program.
My problem is that
I always get 'permission denied' messages when I try to rename the
files. What could possibly cause this?? My compiler is an early
90's version of Borland C (standard issue from school).
I'd be grateful for any help!
John Cooney.
jcooney@netlink.com.au
excerpt:
// ************************** START EDIT MODE **************************
if(toggle == 222) // CTRL+F1 COMBINATION
{
fclose(the_jobs);
big_blank_it();
JOB_TEMP = JOB;
not_this_one = JOB_TEMP.TRANS.job_no;
the_jobs = fopen("jobs.txt", "r+b");
new_file = fopen("temp.txt", "w+b");
fseek (new_file, ((sizeof(JOB))*(0.00)), SEEK_SET);
fseek (the_jobs, ((sizeof(JOB))*(0.00)), SEEK_SET);
while(1)
{
if(JOB.TRANS.job_no != (not_this_one-1.00))
{
fread(&JOB, sizeof(JOB), 1, the_jobs);
fseek(the_jobs, ((sizeof(JOB))*(0.00)), SEEK_CUR);
fwrite(&JOB, sizeof(JOB), 1, new_file);
fseek(new_file, ((sizeof(JOB))*(0.00)), SEEK_CUR);
cprintf("JOB.TRANS.job_no = %f", JOB.TRANS.job_no);
getch();
}
else
break;
}
fwrite(&JOB_TEMP, sizeof(JOB), 1, new_file);
fseek(the_jobs, sizeof(JOB), SEEK_CUR);
textcolor(LIGHTGREEN);
cprintf("JOB.TRANS.job_no = %f", JOB_TEMP.TRANS.job_no);
no_of_records = 0;
while (1)
{
no_of_records = JOB.TRANS.job_no;
fread(&JOB, sizeof(JOB), 1, the_jobs);
if(no_of_records == JOB.TRANS.job_no) //
break;
fseek(the_jobs, 0.00, SEEK_CUR);
fwrite(&JOB, sizeof(JOB), 1, new_file);
textcolor(LIGHTRED);
cprintf("JOB.TRANS.job_no = %f", JOB.TRANS.job_no);
getch();
}
fclose(the_jobs);
fclose(new_file);
strcpy(oldname, "jobs.txt");
strcpy(newname, "jobs.old");
/* Rename jobs.txt file to jobs.old */
if(rename(oldname, newname) == 0)
{
cprintf("File Renamed %s to %s.\n", oldname, newname);
}
else
{
clrscr();
perror("rename ");
}
strcpy(oldname, "temp.txt");
strcpy(newname, "jobs.txt");
/* Rename "temp.txt" file to (the new) jobs.txt */
if(rename(oldname, newname) == 0)
{
cprintf("File Renamed %s to %s.\n", oldname, newname);
}
else
perror("rename ");
getch();
goto SEARCH_AGAIN;
}
if(toggle == 262) // F12 KEY
{
big_blank_it();
edit_select_equip();
edit_display_equip();
//goto EDIT_RECORD_AGAIN;
}
if(toggle == 200) // UP ARROW KEY
{
edit_display_equip();
getch();
big_blank_it();
//goto EDIT_RECORD_AGAIN;
}
if(toggle == 27)
break;
} // end 'edit' while
} // end if
//***********************************************************************
// EDIT MODE ENDED
--
comp.lang.c.moderated - moderation address: clcm@plethora.net
Technical Details
Message-ID:
<clcm-19990614-0023@plethora.net>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!mat.uni.torun.pl!news.nask.pl!orion.cst.tpsa.pl!news.icm.edu.pl!nntp.primenet.com!hermes.visi.com!news-out.visi.com!chippy.visi.com!news-out.visi.com!ptah.visi.com!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!mat.uni.torun.pl!news.nask.pl!orion.cst.tpsa.pl!news.icm.edu.pl!nntp.primenet.com!hermes.visi.com!news-out.visi.com!chippy.visi.com!news-out.visi.com!ptah.visi.com!not-for-mail X-Old-trace: news.netlink.com.au 929287966 30492 203.62.225.52 (13 Jun 1999 15:32:46 GMT) Subject: rename function problem . . . 'permission denied' Approved: clc@plethora.net From: "John Cooney" <jcooney@netlink.com.au> X-Newsreader: Microsoft Outlook Express 4.72.2106.4 Organization: Australian Netlink Return-Path: <news@news.netlink.com.au> Lines: 126 X-Old-complaints-to: news@netlink.com.au Newsgroups: alt.comp.lang.learn.c-c++,comp.lang.c,comp.lang.c.moderated,comp.programming,ctdl.lang.c,it.comp.lang.c,japan.comp.lang.c,pl.comp.lang.c,relcom.comp.lang.c-c++,slac.lang.c X-Mimeole: Produced By Microsoft MimeOLE V4.72.2106.4 Message-ID: <clcm-19990614-0023@plethora.net> Originator: clcm@plethora.net (Comp Lang C'Moderated) Date: Mon, 14 Jun 1999 20:30:52 GMT NNTP-Posting-Host: 205.166.146.1 X-Complaints-To: abuse@plethora.net X-Trace: ptah.visi.com 929392252 205.166.146.1 (Mon, 14 Jun 1999 15:30:52 CDT) NNTP-Posting-Date: Mon, 14 Jun 1999 15:30:52 CDT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit