首页 > 学院 > 开发设计 > 正文

<The C programming language> 语言测试 2

2019-11-06 07:04:17
字体:
来源:转载
供稿:网友

测试以下内容:

1、文件读写操作:“在读和写的交叉过程中,必须调用fflush函数或文件定位函数”

2、remove()

3、rename()

4、tmpnam()

#include <stdio.h>#include <stdlib.h>#include <string.h>int main(void){	char *chp = 0;	PRintf("TMP_MAX = %d/n",TMP_MAX);	for(int i = 0;i < 10;i++){		chp = tmpnam(NULL);		printf("%s/n",chp);	}	char c, *p = chp;	int i = 0;	while ((c = *p++) && c != EOF)		if (c == '//')			i = p - chp;	char *tmp = chp + i;	printf("/nThe last temp file name is %s./n",tmp);//	for(i = 0;i < 100;i++)//		rand();	int r;	r = rand();	FILE *fp;	fp = fopen(tmp,"a+");	fprintf(fp,"%i",r);	fseek(fp,0,SEEK_SET);		int rr;	fscanf(fp,"%d",&rr);	printf("The random number is %d./n",rr);		if (fclose(fp))		printf("Can't close the file./n");	if (!rename(tmp,"new.txt"))		printf("file name CHANGED HERE!/n");	remove("new.txt");}


上一篇:2144: 跳跳棋

下一篇:CUDA笔记

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表