fopen.c

来自「一些linux基本函数的测试集,给像我一样的新手看看」· C语言 代码 · 共 60 行

C
60
字号
#include <stdio.h>

//int main()   //file write(fputc)
//{
//	FILE * fp;
//	char *j;
//	char *a;
//	
//	j="this is our journey,
//journey though life.";
//	
//	fp=fopen("result.txt","w+");
//	
//	for(;*(j)!='\0';j++)
//		fputc(*j,fp);
//	
//	fclose(fp);
//	return 0;
//}
int main()     //file write(fputs)
{
	FILE * fp;
	char * str;
	char c;
	str = "can't believe that I'm the fool again,
I thought this love would never end.";
	fp=fopen("result.txt","r+");
	while((c=fgetc(fp))!='\0')
		continue;
	fputs(str,fp);
	fclose(fp);
	return 0;
}

//int main()    //file read(fgetc)
//{
//	FILE * fp;
//	int c;
//	fp = fopen("result.txt","r");
//	while((c=fgetc(fp))!=EOF)
//		printf("%c",c);
//	fclose(fp);
//	return 0;	
//}

//int main()    //file read(fgets)
//{
//	FILE * fp;
//	fp = fopen("result.txt","r");
//	char s[80];
//	fgets(s,80,fp);
//
//	fclose(fp);
//	printf("fgets test:%s\n",s);
//	return 0;
//}

//int main()   //

⌨️ 快捷键说明

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