Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C language - Fscanf and sprint commands in unix environment

Tags:

c

unix

printf

scanf

I am trying to read file with 30 rows and 5 columns with separator of "tab". Each time I get only part of the rows. In the windows environment it's working good. Any idea why in unix it is not working?

while (fscanf(FFMapFile, "%s\t%s\t%s\t%s\t%s\t", fnfMap[i].COS_ID, fnfMap[i].FF_First_Act, fnfMap[i].FF_Next_Act, nfMap[i].Free_FF_allowed, fnfMap[i].FF_Change_Charge) != EOF)
{ 
    sprintf(s,"%s\t%s\t%s\t%s\t%s\t", nfMap[i].COS_ID, fnfMap[i].FF_First_Act, fnfMap[i].FF_Next_Act, fnfMap[i].Free_FF_allowed, fnfMap[i].FF_Change_Charge);
    error_log(s,ERROR);
    i++; }
like image 262
user386530 Avatar asked Nov 30 '25 04:11

user386530


1 Answers

The \t characters in your fscanf() string are not necessary - tabs are whitespaces, so you may just as well say "%s%s%s%s" - conceivably, the two scanf implementations are treating them differently. Also, you should be checking for fscanf returning a value other than EOF but not equal to the number of expected conversions, which would indicate a conversion error of some sort.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!