初级启示者
#include <stdio.h>
#include <string.h>
int
fpreadline(
char
a[])
{
int
k=0;
FILE
*fp =
fopen
(
"C:\\Users\\Administrator\\Desktop\\1.txt"
,
"r"
);
if
(NULL == fp)
{
printf
(
"failed to open dos.txt\n"
);
return
1;
}
while
(!
feof
(fp))
{
fgets
(&a[k], 1000, fp);
if
(
feof
(fp))
{
break
;
}
printf
(
"%s"
, &a[k]);
k=
strlen
(a)-1;
printf
(
"请输入你要添加的内容:"
);
gets
(&a[k]);
k=
strlen
(a);
a[k]=10;
a[++k]=0;
}
fclose
(fp);
}
int
fpwrite(
char
a[])
{
FILE
*fp =
fopen
(
"C:\\Users\\Administrator\\Desktop\\1.txt"
,
"w+"
);
if
(NULL == fp)
{
printf
(
"failed to open dos.txt\n"
);
return
1;
}
fputs
(a,fp);
fclose
(fp);
}
int
main()
{
char
a[10000]={0};
fpreadline(a);
fpwrite(a);
return
0;
}
初级启示者