chatwrite.c

来自「在linux下的聊天软件」· C语言 代码 · 共 82 行

C
82
字号
/*
  chatwrite.c
  
  For Free Chat
  
  By Bill Kendrick, ported to NT by Patrick Stepp
  kendrick@zippy.sonoma.edu, stepp@adelphia.net
  http://zippy.sonoma.edu/kendrick/
  
  September 29, 1996 - October 3, 1996 / January 13, 1997 / June 10, 1997
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "readline.h"
#include "chatwrite.h"
#include "copyback.h"
#include "defines.h"
#include "myopen.h"


void chatwrite(char * time, char * name, char * text)
{
  char temp[STRLEN];
  int i, j;
  FILE * fi, * fo;
  
  
  if (LOG == YES || (LOG == SMALL && strcmp(name, "JOIN") == 0))
    {
      fo = myopen("C:/chat/chat.logs", "a");
      if (fo == NULL)
	{
	  printf("System is down! (can't append to \"chat.logs\")\n");
	  exit(0);
	}
      
      fprintf(fo, "%s\t", time);
      fprintf(fo, "%s\t", name);
      fprintf(fo, "%s\n", text);
      
      fclose(fo);
    }
  
  
  fo = myopen("C:/chat/chat.tmp", "w");
  if (fo == NULL)
    {
      printf("System is down! (can't create \"chat.tmp\")\n");
      exit(0);
    }
  
  fprintf(fo, "%s\n", time);
  fprintf(fo, "%s\n", name);
  fprintf(fo, "%s\n", text);
  
  fi = myopen("C:/chat/chat.dat", "r");
  if (fi == NULL)
    {
      printf("System is down! (can't read \"chat.dat\")\n");
      exit(0);
    }
  
  for (i = 0; i < MAXLINES; i++)
    {
      for (j = 0; j < 3; j++)
	{
	  readline(fi, temp);
	  if (!feof(fi))
	    fprintf(fo, "%s\n", temp);
	  else
	    i = MAXLINES;
	}
    }      
  
  fclose(fi);
  fclose(fo);
  
  copyback("C:/chat/chat.dat", "C:/chat/chat.tmp");
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?