linux创建随机个数文件,linux创建随机数并写文件处理

本文介绍了如何在Linux系统中使用C语言创建一个名为rondom_create_score.c的程序,该程序能生成随机数并将其写入到文本文件中。程序详细展示了srand()和rand()的用法,以及文件操作函数如fopen(), fwrite(), fread(), fseek()和fclose()的应用。在写入文件时,未将字符串结束符''写入,而在读取时手动添加,确保正确输出。" 105808305,1426301,深信服安全实践:外部威胁防护与勒索病毒对策,"['网络安全', '安全防护', '勒索病毒', '威胁情报', '深信服']
摘要由CSDN通过智能技术生成

一、案例代码

/****************************************************************

* Name   : rondom_create_score.c

* Author : dyli2000

* Date   : 20121031

* Description :

* This file show how to create a rondom data and

* write it to a txt.And show the function application of

* file operate.

****************************************************************/

#include

#include

#include

#define TIMES 20

//#define DEBUG

int main()

{

FILE *fp;

int count = 0;

char string[200];

int k = 0;

memset(string,'0',200);

fp = fopen("test.txt","w+");

if(fp == NULL)

perror("fail!");

/* step1,call srand.It's return value is "void" */

srand((unsigned int)time(0));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值