LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Scan ASCII numbers in german format

Hi all!

I have the following problem:

I need to read ASCII files with lots of sensor data. There are 102 float values per line. Each line ends up with a CR LF (\r\n). The one who created the data files decided to use a TAB (\t) as delimiter and a comma as decimal separator.

Is there a way to read this files into an array?

 

Best regards,

Thomas

 

0 Kudos
Message 1 of 6
(3,578 Views)

Have a look at the ScanFile (, ); function from the Formatting and I/O library. The rep modifier will help with arrays Smiley Wink

 

You may also want to have a look at the examples here

0 Kudos
Message 2 of 6
(3,572 Views)

Yes, I read it already, but couldn't find a way that ScanFile will interpret something like "1,234" as real number. If I change all the ',' to '.' in advance, it will work perfectly.

0 Kudos
Message 3 of 6
(3,563 Views)

Oh, I see... the usual German <--> English data format problem...

 

You can treat it on the OS side by changing your language settings.

 

Or, programmatically, ypu could possibly read your file line by line (ReadLine), in the line buffer replace the comma with a dot (e.g. using putchar()), and then use Scan instead of ScanFile on the line buffer...

 

0 Kudos
Message 4 of 6
(3,555 Views)

I guess that I have to correct myself: changing the OS locale does affect some programs in how they treat numbers but it will not change the decimal point character of C... so please ignore the first comment of my last post

0 Kudos
Message 5 of 6
(3,551 Views)

Ok. Then I will read the file with ReadLine(,,);, transform them, and scan them afterwards. Hopefully things don't get mixed up.

THX

Thomas

0 Kudos
Message 6 of 6
(3,545 Views)