¹ØÓÚprintf()µÄÒÉÎÊ
ÏÂÃæÕâ¶Î³ÌÐòÍê³ÉÔÚstu.txtÎļþÖÐдÈëÁ½¸ö×Ö·û´®µÄ²Ù×÷Ê×ÏÈ,ÔÚÎļþµÄ¿ªÍ·´¦Ð´Èë×Ö·û´®ch1
È»ºó,ÔÚÎļþµÄ½áβ´¦Ð´Èë×Ö·û´®ch2
´úÂëÈçÏÂ:
#include<stdio.h>
#include<stdlib.h>
void main()
{
FILE *fp;
char c;
char ch1[]="1234";
char ch2[]="^^^QW!!asd!!WQ^^^";
if((fp=fopen("stu.txt","r+"))==NULL)
{
printf("ÐèҪн¨Á¢Ò»¸östu.txt\n");
exit(0);
}
fprintf(fp,"%s\n",ch1);/*ÔÚÎļþµÄ¿ªÍ·´¦Ð´Èë×Ö·û´®ch1*/
while(!feof(fp))
{
c=fgetc(fp);
}
fprintf(fp,"%s",ch2);/*ÔÚÎļþµÄ½áβ´¦Ð´Èë×Ö·û´®ch2*/
fclose(fp);
}
µ«Ö´ÐÐÈ´ÊÇ´íµÄ,¸ù±¾¾ÍÊÇËÀÑ»·.
Ð޸ĺó·¢ÏÖ.........
1.Èô½«fprintf(fp,"%s\n",ch1);È¥µô,ÔòÄÜÔÚÎļþ½áβ´¦Ð´Èë×Ö·û´®ch2
2.ÈôÔÚÖ´ÐÐÍêfprintf(fp,"%s\n",ch1);ÕâÒ»¾äºó½«Îļþfclose(fp),
ÔÚfopen(fp),Ôò¿ÉÒÔÍê³ÉÉÏÊöÁ½Ïî²Ù×÷(¸Ä¶¯ºóÍêÕû´úÂëÈçÏÂ)
Çë´ó¼Ò°ïæ¿´¿´ÎªÊ²Ã´²»ÄÜÓÃÉÏÃæµÄ´úÂëʵÏÖÄÇÁ½Ïî²Ù×÷£¡£¡£¡£¡
#include<stdio.h>
#include<stdlib.h>
void main()
{
FILE *fp;
char c;
char ch1[]="1234";
char ch2[]="^^^QW!!asd!!WQ^^^";
if((fp=fopen("stu.txt","r+"))==NULL)
{
printf("ÐèҪн¨Á¢Ò»¸östu.txt\n");
exit(0);
}
fprintf(fp,"%s\n",ch1);
fclose(fp);/*¹Ø±Õ*/
fp=fopen("stu.txt","r+");/*´ò¿ª*/
while(!feof(fp))
{
c=fgetc(fp);
}
fprintf(fp,"%s",ch2);
fclose(fp);
}