#include <stdio.h> main(){ FILE *fp;char *p;int i=0;char str[10];fp=fopen("C:\\Users\\Administrator\\Desktop\\c程序设计\\text.txt","w");fputs("hello!",fp);fp=fopen("C:\\Users\\Administrator\\Desktop\\c程序设计\\text.txt","r");fgets(str,5,fp);for(i;i<10;i++)printf("str=%s",str[i]);getchar();}
2 回答

慕标琳琳
TA贡献1830条经验 获得超9个赞
#include <stdio.h>
int
main(
void
)
{
FILE
*fp;
char
str[10]={0};
if
((fp=
fopen
(
"D:/123/text.txt"
,
"w+"
))==NULL)
// 文件必须已经存在
{
printf
(
"ERROR!\n"
);
exit
(1);}
fputs
(
"hello!"
,fp);
fseek
(fp,0,SEEK_SET);
// 把当前指针移到文件开始处
fgets
(str,7,fp);
printf
(
"str=%s"
,str);
fclose
(fp);
return
0;
}
- 2 回答
- 0 关注
- 105 浏览
添加回答
举报
0/150
提交
取消