c語言-同步讀寫檔案
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
printf("Hello world!\n");
FILE *pf;
//int i=0;
char buf[513];
char buf0[100];
pf=fopen("runoob.txt","r");
FILE *fp_w = fopen("data_out.txt", "w");
while(fgets(buf,512,pf) != NULL)
{
printf("%s",buf);
//printf("\n");
fprintf(fp_w,"%s",buf);
}
fclose(pf);
printf("\n");
system("pause");
return 0;
}
runoob.txt
aaaa
fdfddf
data_out.txt
aaaa
fdfddf
#include <stdlib.h>
#include <string.h>
int main()
{
printf("Hello world!\n");
FILE *pf;
//int i=0;
char buf[513];
char buf0[100];
pf=fopen("runoob.txt","r");
FILE *fp_w = fopen("data_out.txt", "w");
while(fgets(buf,512,pf) != NULL)
{
printf("%s",buf);
//printf("\n");
fprintf(fp_w,"%s",buf);
}
fclose(pf);
printf("\n");
system("pause");
return 0;
}
runoob.txt
aaaa
fdfddf
data_out.txt
aaaa
fdfddf
留言
張貼留言