Posted on 2008-04-12 21:05
把大海藏到心里 阅读(137)
评论(1) 编辑 收藏 所属分类:
c/c++
#include <stdio.h>
#define OK 1
#define ERROR 0
void out(char* str);
int main()
{
FILE *fp;
char c[1];
char* d;
char* myText1="abcdasdfasdfasdfasdfasdf\\nasdfasdf";
char* text1="aa";
long length=0;
clrscr();
out("***************** Write File ****************\n");
fp=fopen("test.txt","w+");
if(fp!=NULL)
{
d=myText1;
while(*d++)
{
fwrite(d,sizeof(char),1,fp);
printf("%d:%c\t",d,*d);
}
/* fprintf(fp,"%s",text1); */
fclose(fp);
out(myText1);
}
out("\n*************** Read File *****************\n");
fp=fopen("test.txt","r+");
if(fp!=NULL)
{
while(!feof(fp))
{
++length;
fread(&c,sizeof(char),1,fp);
printf("%c",c[0]);
c[0]='';
}
printf("\nFile Length:%ld\n",length);
fclose(fp);
}
getch();
return 0;
}
void out(char* str)
{
printf("\n%s\n",str);
}