08-09-2013 02:21 AM
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
08-09-2013 02:39 AM - edited 08-09-2013 02:44 AM
Have a look at the ScanFile (, ); function from the Formatting and I/O library. The rep modifier will help with arrays
You may also want to have a look at the examples here
08-09-2013 03:44 AM
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.
08-09-2013 04:26 AM
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...
08-09-2013 05:06 AM
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
08-09-2013 05:54 AM
Ok. Then I will read the file with ReadLine(,,);, transform them, and scan them afterwards. Hopefully things don't get mixed up.
THX
Thomas