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

慕標(biāo)琳琳
TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超9個(gè)贊
#include <stdio.h>
int
main(
void
)
{
FILE
*fp;
char
str[10]={0};
if
((fp=
fopen
(
"D:/123/text.txt"
,
"w+"
))==NULL)
// 文件必須已經(jīng)存在
{
printf
(
"ERROR!\n"
);
exit
(1);}
fputs
(
"hello!"
,fp);
fseek
(fp,0,SEEK_SET);
// 把當(dāng)前指針移到文件開(kāi)始處
fgets
(str,7,fp);
printf
(
"str=%s"
,str);
fclose
(fp);
return
0;
}
- 2 回答
- 0 關(guān)注
- 131 瀏覽
添加回答
舉報(bào)
0/150
提交
取消