LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to read from a certain location is a file?

hi! i am new to programing and i have a problems abt reading from a file. i have write the following to a file using FmtFile :

10 (a numbers)
name,phone,product (some strings)
9 (a numbers)

when i user ScanFile to read the second number(9 in the above example), i got a wrong value. the command i use is:

ScanFile (filehandle, "%d", &number1);
ScanFile (filehandle, "%s[t44]%s[t44]%s",name, phone product);
ScanFile (filehandle, "%d", &number2);

number1 and number 2 are integers and name, phone and product are char arrays.

can anyone tell me where have i gone wrong? or maybe someone can tell me how can i read the 2nd number without reading the 1st number
and the strings.
0 Kudos
Message 1 of 3
(3,036 Views)
Let's look at your file: if I correctly interpret your question, one row in it should like like this:
10,name,phone,product,9
In this case you could use the following formatting string to read all data from the string:
"%d[x]%s[xt44]%s[xt44]%s[xt44]%d"
[x] means to discard terminator, in order to read from strings, for example, "name" and not "name,". It's important in this case to put ALL field separators.
Maybe your problem is that in the file you don't have separators between strings and numbers: in this case the last "%s" should read the '9' inside the last string and the subsequent "%d" matches with incorrect area in the file (end-of-line or next row).
Hope this help


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 3
(3,036 Views)
hi Roberto!
thanks for your help. you are right. the solution seems so obvious and yet i didn't realise it. i managed to solve the problem by adding a "\n" to the first and second FmtFile() function.

thanks again
0 Kudos
Message 3 of 3
(3,036 Views)