| | |
read data file in C
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2007
Posts: 5
Reputation:
Solved Threads: 0
Dear all;
I have problem in reading data file in C. I have data like this:
00:00:00 R- 0.0654 345 +19
00:01:00 R+ 1.5678 324 +19
00:02:00 2.3456 315 +19
00:03:00 R- 1.2352 324 +19
........................ next until 1440 lines
What i want is only the data in third column, but as we see in second column sometimes is empty. I try read the data as string first like :
fscanf (fdin1, "%s %s %s %s %s",data1, data2, data3, data4, data5);
but in third coulumn i have trouble, because data5 = 00:03:00 not +19.
could help me how to read the data in the better way?
Thank you very much
Marzuki
I have problem in reading data file in C. I have data like this:
00:00:00 R- 0.0654 345 +19
00:01:00 R+ 1.5678 324 +19
00:02:00 2.3456 315 +19
00:03:00 R- 1.2352 324 +19
........................ next until 1440 lines
What i want is only the data in third column, but as we see in second column sometimes is empty. I try read the data as string first like :
fscanf (fdin1, "%s %s %s %s %s",data1, data2, data3, data4, data5);
but in third coulumn i have trouble, because data5 = 00:03:00 not +19.
could help me how to read the data in the better way?
Thank you very much
Marzuki
Read each line using fgets(), as in
The key point is to read a whole line using fgets(). What you do afterwards is up to you in terms of validation and conversion.
c Syntax (Toggle Plain Text)
char buff[BUFSIZ]; while ( fgets( buff, sizeof buff, fdin1 ) != NULL ) { if ( sscanf( buff, "%s %s %s %s %s",data1, data2, data3, data4, data5) == 5 ) { // could be a line like // 00:00:00 R- 0.0654 345 +19 } else { // might be a line like // 00:02:00 2.3456 315 +19 } }
![]() |
Similar Threads
- help me to read my data file:(( (C)
- Help Please, how do i read from text file into array? (Visual Basic 4 / 5 / 6)
- read text file (C)
- read data from file (C++)
Other Threads in the C Forum
- Previous Thread: 16 bit to 8 bit
- Next Thread: Factorial program using an array.
| Thread Tools | Search this Thread |
#include * append array arrays asterisks bash binarysearch calculate changingto char character cm copyimagefile creafecopyofanytypeoffileinc createprocess() database directory dynamic execv feet fgets file floatingpointvalidation fork forloop framework function getlogicaldrivestrin givemetehcodez global grade gtkwinlinux hacking histogram ide include incrementoperators input intmain() iso kernel keyboard kilometer km license linked linkedlist linux list lists locate looping loopinsideloop. lowest matrix meter microsoft mqqueue number oddnumber odf opensource openwebfoundation overwrite owf pdf performance pointer posix probleminc process program programming radix recursion recv recvblocked research reversing scripting segmentationfault sequential single socket socketprogramming standard strchr string systemcall testing threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi






