fscanf选择读取文件中的数据
时间:2011-01-20 来源:IT播求
比如有文件a
内容为:
M=3
#include<stdio.h> int main() { FILE *fp; int n; fp = fopen("a","r"); if(fp == NULL) printf("fopen error"); fscanf(fp,"M=%d",&n); printf("n=%d",n); return 0; }
这个程序可以选择性的读取3到变量n中。
这在从文件中选择性地读取数据时很有用。
相关阅读 更多 +