【发布时间】:2018-02-03 00:56:24
【问题描述】:
嘿,我想知道是否有可能 函数 fscanf 对从文件中读取的整数进行操作,然后再将其存储到数组中。
例如:
for(int i = 0 ;i < size;i++){
//Here it just stores the number read
fscanf(file, "%d", &arr[i]);
//However I'm trying to do such a thing(substract the number by 1 everytime)
fscanf(file, "%d -1 ", &arr[i]);
printf("\n%d",arr[i]);
}
提前致谢
【问题讨论】:
-
呃.....没有。
-
不,这是不可能的。读取输入,然后在您的代码中处理它。
-
这是不可能的,但如果你愿意,你可以编写一个包装函数或宏来做到这一点:
#define FSCANF_SUBTRACT_1(FILE, FMT, VAR_PTR) do { int result = fscanf(FILE, FMT, VAR_PTR); --*VAR_PTR; return result; } while (false)