#include<stdio.h>
FILE*stream
void main(void)
{
long l
float fp
char s[81]
char c
stream=fopen("fscanf.out","w+")
if(stream==NULL)
printf("Thefilefscanf.outwasnotopened\n")
else
{
fprintf(stream,"%s%ld%f%c","hello world",
65000,3.14159,'x')
/*Setpointertobeginningoffile:*/
fseek(stream,0L,SEEK_SET)
/*Readdatabackfromfile:*/
fscanf(stream,"%s",s)
fscanf(stream,"%ld",&l)
fscanf(stream,"%f",&fp)
fscanf(stream,"%c",&c)
/*Outputdataread:*/
printf("%s\n",s)
printf("%ld\n",l)
printf("%f\n",fp)
printf("%c\n",c)
fclose(stream)
}
}
举例来说:FILE*fp=fopen("dict.txt","r")charbuf[1024]if(fp!=(FILE*)NULL){while(fgets(buf,sizeof(buf),fp))//从文件慧稿誉中读入一行字符串,保存在前段敬升buf中,直到读完所有字符串{//处理读入的字符串buf}fclose(fp)}使用c语言库中的_access()函数升睁判断文件夹是否存在。该函数搏笑档的参数中文件夹路径中不允许由空格。因此下面的代码运行错误。 其实检查的是e盘的my文基乱件夹。代码:#include <io.h
#include <stdio.h
#include <stdlib.h
void main( void ){/* Check for existence */
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)