⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 random.c

📁 Free Chat beta release 2 fot linux,采用C语言写的运行在linux下的聊天室程序
💻 C
字号:
/*  random.c    By Bill Kendrick  New Breed Software  February 14, 1996, May 30, 1996    Randomly picks one line out of a file and displays it.  Based on the "random" directive from my "counter.cgi" 'CGI-Side-Include'  program.  Call with: "random file"  Example:    Random quote:  <!--#exec cmd="random quotes.html" -->*/#include <stdio.h>#include <sys/time.h>#include <sys/timeb.h>#include <sys/types.h>int rnd(int n){  int r;  struct timeval t;    gettimeofday(&t, NULL);  r=t.tv_sec + t.tv_usec;  srand(r);    r=(t.tv_usec+rand())%n;  return(r);}int main(int argc, char * argv[]){  int many, pick;  FILE * fi;  char the_lines[500][1024], line[1024];    if (argc != 2)    {      printf("<!-- Usage: random file -->\n");      exit(0);    }    fi = fopen(argv[1], "r");  if (fi == NULL)    {      printf("<!-- random: Can't open \"%s\" file! -->\n", argv[1]);      exit(0);    }    many = 0;  do    {      fgets(line, 1024, fi);      if (!feof(fi))	{	  strcpy(the_lines[many], line);	  many = many + 1;	}    }  while(!feof(fi));  fclose(fi);  pick = rnd(many);;  printf("<!-- Picked: %d / %d -->\n", pick, many);  printf("%s", the_lines[pick]);    exit(0);}

⌨️ 快捷键说明

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