📄 file.c
字号:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define NUM 50
void main(void)
{
int source1[NUM];
int source2[NUM];
int i=NUM,j=NUM;
FILE *fp;
srand(time(NULL));
for(i=0;i<NUM;i++)
{
source1[i]=rand()%2000;
}
/****************************************/
/*写文件 data1.dat*/
fp=fopen("e:\\data1.dat","wb");
if(fp==NULL)
{
printf("the file cannot be open.\n");
exit(0);
}
fwrite(source1,sizeof(int),NUM,fp);
fclose(fp);
for(j=0;j<NUM;j++)
{
source2[j]=rand()%2000;
}
/********************************************/
/*写文件 data2.dat*/
fp=fopen("e:\\data2.dat","wb");
if(fp==NULL)
{
printf("the file cannot be open.\n");
exit(0);
}
fwrite(source2,sizeof(int),NUM,fp);
fclose(fp);
/********************************************/
printf("File write success!\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -