file.c

来自「归并外排序,要先运行file程序」· C语言 代码 · 共 43 行

C
43
字号
#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 + =
减小字号Ctrl + -
显示快捷键?