🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #661

rename function problem . . . 'permission denied'

#661
From: John Cooney
Date: Mon, 14 Jun 1999 00:00
127 lines
5174 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: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 114592,1eeab4214eed5a1a,start
X-Google-Attributes: gid114592,public
X-Google-Thread: f4614,1eeab4214eed5a1a,start
X-Google-Attributes: gidf4614,public
X-Google-Thread: 100850,1eeab4214eed5a1a,start
X-Google-Attributes: gid100850,public
X-Google-Thread: 108717,1eeab4214eed5a1a,start
X-Google-Attributes: gid108717,public
X-Google-Thread: 10f67c,1eeab4214eed5a1a,start
X-Google-Attributes: gid10f67c,public
X-Google-Thread: 1014db,1eeab4214eed5a1a,start
X-Google-Attributes: gid1014db,public
X-Google-Thread: fab7a,1eeab4214eed5a1a,start
X-Google-Attributes: gidfab7a,public
X-Google-Thread: f869b,1eeab4214eed5a1a,start
X-Google-Attributes: gidf869b,public
From: "John Cooney" <jcooney@netlink.com.au>
Subject: rename function problem . . .   'permission denied'
Date: 1999/06/14
Message-ID: <clcm-19990614-0023@plethora.net>
X-Deja-AN: 489568514
X-Old-trace: news.netlink.com.au 929287966 30492 203.62.225.52 (13 Jun 1999 15:32:46 GMT)
Approved: clc@plethora.net
X-Mimeole: Produced By Microsoft MimeOLE V4.72.2106.4
X-Complaints-To: abuse@plethora.net
X-Trace: ptah.visi.com 929392252 205.166.146.1 (Mon, 14 Jun 1999 15:30:52 CDT)
Organization: Australian Netlink
X-Old-complaints-to: news@netlink.com.au
NNTP-Posting-Date: Mon, 14 Jun 1999 15:30:52 CDT
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
Originator: clcm@plethora.net (Comp Lang C'Moderated)