|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 Mr.HO 于 2018-6-20 16:09 编辑
#define _CRT_SECURE_NO_WARINGS
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include <windows.h>
void main0001()
{
FILE *fp=NULL;
char a[]="ffffffff's project!gogogogogogogo";
char *filename="ffff.ini";
int i;
fp=fopen(filename,"w+");
if (!fp)
{
return;
}
for (i=0;i<sizeof(a);i++)
{
fputc(a[i],fp);
}
fclose(fp);
system("pause");
return;
}
void main02(void)
{
FILE *fp=NULL;
char *fileName="ffff.ini";
char *Mode="r+";
int i;
fp=fopen(fileName,Mode);
if ( !fp)
{
return;
}
while(!feof(fp))
{
printf("%c",fgetc(fp));
Sleep(1000);
}
fclose(fp);
system("pause");
return;
}
void main03(void)
{
FILE *fp=NULL;
const char *filName="fff.ini";
const char *Mode="r+";
char buf[1024]={0};
int i=0;
int j;
fp=fopen(filName,Mode);
if (!fp)
{
return;
}
while(i<9)
{
i++;
sprintf(buf,"test%d%d%d\n",i,i,i);
j=fputs(buf,fp);
if (j!=-1)
{
printf("the file write is succ!\n");
}
}
fclose(fp);
system("pause");
return;
}
void main06(void)
{
const char *fileName="fffff.ini";
const char *Mode="r+";
char buf[1024];
FILE *fp=NULL;
fp=fopen(fileName,Mode);
if (!fp)
{
return;
}
while(!feof(fp))
{
char *p;
memset(buf,0,sizeof(buf));
p=fgets(buf,sizeof(buf),fp);
if (p)
{
printf("%s",buf);
}
}
fclose(fp);
system("pause");
}
typedef struct T
{
char name[64];
int age;
}Teacher;
void mian_fwrite()
{
FILE *fp=NULL;
Teacher t[3];
int i;
fp=fopen("bin.data","wb+");
if (!fp)
{
return;
}
for(i=0;i<3;i++)
{
int j;
sprintf(t[i].name,"%d%d%d",i+1,i+1,i+1);
t[i].age=i+30;
j=fwrite(&t[i],sizeof(Teacher),1,fp);
if (j)
{
printf("write succ!\n");
}
}
fclose(fp);
return;
}
void mainfread()
{
FILE *fp=NULL;
Teacher t[3];
int i;
fp=fopen("bin.data","rb");
if (!fp)
{
return;
}
for (i=0;i<3;i++)
{
int k;
k=fread(&t[i],sizeof(Teacher),1,fp);
if (k)
{
printf("%s,%d\n",t[i].name,t[i].age);
}
}
fclose(fp);
return;
}
void main(void)
{
mainfread();
system("pause");
return;
} |
|