70,024
社区成员




#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp;
char str1[50],str2[50];
int i;
//从文件中读取
fp=fopen("data.txt","r");
if(!fp)
{
printf("Can not open the file!");
exit(0);
}
fgets(str1,50,fp);
fgets(str2,50,fp);
printf("%s\n",str1);
printf("%s\n",str2);
fclose(fp);
for(i=2;i<10;++i)
{
str1[i]='0';
str2[i]='0';
}
str1[10]='1';
str2[10]='1';
//写入文件
fp=fopen("another.text","w");
if(!fp)
{
printf("Can not open the file!");
exit(0);
}
fputs(str1,fp);
fputs(str2,fp);
printf("成功写入文件!");
fclose(fp);
system("pause");
return 0;
}
#include <stdio.h>
#include <string.h>
void main ()
{
FILE *fp,*fp1;
char buf[128];
char i='1';
int j;
fp=fopen("a.txt","r");
fp1=fopen("b.txt","w");
while(!feof(fp))
{
fgets(buf,128,fp);
for(j=2;j<9;j++)
buf[j]='0';
buf[j]=i;
i++;
fprintf(fp1,"%s\n",buf);
}
fclose(fp);
fclose(fp1);
}