求大神指点怎样从文件中读取数据!!

int main()
{
double data;
FILE *fp=fopen("e://in.txt","r");
if(!fp)
{

printf("can't open file\n");

return -1;
}
while(!feof(fp))
{

fscanf(fp,"sfdf =%lf",&data);

printf("%lf",data);
}
printf("\n");
fclose(fp);
return 0;
}

我文件里的内容是
sfdf = 12.222 njngfngkx
注意行的前面有空格。。。。为什么用fscanf得不出12.222呢??

字符串查找,strstr等获取等号的位置,然后substr截取子字符串。

用fscanf()读文件,可以格式化读取。

读取出来字符串之后,判断+,然后从它开始截取之后的所有数字字符,直到非数字字符或结尾

格式化字符串注意空格。

http://bbs.csdn.net/topics/370023867

int main()
{
double data;
FILE *fp=fopen("./in.txt", "r");
if(!fp) {
printf("can't open file\n");
return -1;
}

    while(!feof(fp)) {
            if (fscanf(fp, "%*[^=]= %lf", &data) > 0)
                    printf("%lf", data);
    }
    printf("\n");

    fclose(fp);
    return 0;

}

晕,这代码段插入怎么这么乱啊,也不能再次编辑。。。

fscanf(fp,"sfdf =%lf",&data);百分号前加个空格试试。夜里无聊看手机的,也没法帮你测试。