Re: Writing to a file

From: Thomas Arp (
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 ""
  static char 1_buf[MAX_INPUT_LENGTH];
  FILE *fl; /* declare the file */

       *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 %s", strerror(errno));
       } else {
         fprintf(fl, "%s\n", 1_buf); /* append the string */
         fclose(fl); /* close the file */
       STATE(d) = CON_MENU;
 Standard disclaimer applies - mailer code, not my fault if stuff explodes etc. etc.

Hopes this helps you out a bit..

Welcor 9090

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  |

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