1,fsacnf函数介绍
函数原型:int fscanf(FILE *stream, char *format, arguments...);
参数介绍:FILE *stream 文件指针,即文件流(文件数据存放的地方,要从里面讲数据拿出来);
char *format 格式字符串("%d%2s%"之类的);
arguments 输入列表(地址);
函数功能:从stream中按format格式读取文件到arguments中。
注意: fsacnf遇到换行时结束,遇到空格也结束(这与fgets不同);
示例:
fscanf(stream,"%02s%20s%15s%8s%5s%2s%6s%12s %06s%06s %6s %6s %12s\n"
,s.trans_type,s.f_card_no,s.merchant_no,s.terminal_id
,s.date_exp,s.resp_code, s.auth_id, s.amount, s.time_header
,s.stime1,s.sys_trace_num, s.invoice_v, s.ref_no);
这是stream文件流中一行数据,
021234567890123456111 104110054111334110064381212 00666666000001560000 131230121344 888888 777777 123456789012 0
以上代码从文件流stream中取出字符串,输出到后面的各个字段中,其实这里有一个问题,因为文件中每一行字符串中都有空格,而fsac