Re: Writing to a file

From: Thomas Arp (t_arp@mail1.stofanet.dk)
Date: 09/03/00


> I want to write a buffer straight to a specific file. Simple?
Ok, so someone enters an argument (arg) and you want to put it into a file..
Lets see now..

#define FILE_TO_SAVE "file_name.here"
-snip-
  static char 1_buf[MAX_INPUT_LENGTH];
  FILE *fl; /* declare the file */
-snip-

       *1_buf = '\0'; /* Would rather free this if I could */
       sprintf(1_buf, "%s", arg);
       SEND_TO_Q(1_buf, d);
       SEND_TO_Q("\r\nThank you.\r\n", d);
       if (!(fl = fopen(FILE_TO_SAVE, "wb"))) { /* open the file */
          log("SYSERR: opening file_name.here: %s", strerror(errno));
       } else {
         fprintf(fl, "%s\n", 1_buf); /* append the string */
         fclose(fl); /* close the file */
       }
       STATE(d) = CON_MENU;
       break;
 -snip-
 Standard disclaimer applies - mailer code, not my fault if stuff explodes etc. etc.

Hopes this helps you out a bit..

Welcor
cruelworld.dune.net 9090


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 04/11/01 PDT