LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to find number of rows from and number of eleements from a comma seperated values txt file

Hi to all of u i have a text file like that

1.25,3.2,4,12.2

2.36,12,6,8.8.5

1.25,3.2,4,12.2

 is there any function which can find number of rows from file and how many characters in file and how many values in file excluding commas.

i used scanfile but didnt succedded in my task.

 

 

0 Kudos
Message 1 of 11
(4,693 Views)

File lenght is returned from several functions: GetFileInfo, FileExists...

 

No predefined functions for other tasks I'm afraid: simply... count!

 

1. Number of rows in a file: OpenFile + iterate on ReadLine until end of file

2. Number of fields in a row: having read a file line you can use strtok to loop through it with the appropriate separator counting the number of fields. Look at the examples listed in the help ti understand how to use this function



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 11
(4,686 Views)

sir Roberto if i read use read line function how can i give the loop limit to exit for example if i have a khadim.txt file in which i have a data

1,2,3

4,5,6

7,8,9

now i will use read line function but how to use for loop so that i can iterate some variable for rows

for example

means if i know that how many times i should run for loop than i will also khow how much rows

sir kindly explain me with example consider the data in khadim.txt in above format for example

i m also trying to use strtok function but i mange to use just when i have a data in buffer with different delimiters and then i able to use it.  kindly explain me the task in both ways.

i know that if i use for loop 10 times and also use read line that it will read 10 lines. but the main problem which i want to solve is that i dnt know the number of lines that what will be the end of loop value?

0 Kudos
Message 3 of 11
(4,667 Views)

 

int  x, cnt = 0;

OpenFile ();

// Count lines
While (TRUE) {   x = ReadLine ();   if (x == -1)   {       // Handle I/O error   }   if (x == -2) break;    // End of file   cnt++;   // Count a line }
// Roll back to start of file
SetFilePtr ();

// Read lines and handle them for (x = 0; x < cnt; x++) { ReadLine (); // Scan lines
// .... }

 

This is how I would address the first part of your question.

 

For what refers to strtok I direct you to the help for the function and the examples linked there (timeaxis.prj seems to me the most simple to study).



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 4 of 11
(4,661 Views)

thanku sir Roberto sir another way u told me about using strtok function how would we use that function to count lines?

 

0 Kudos
Message 5 of 11
(4,655 Views)

Using strtok to count lines in file is done the same way as scanning elements in a line provided you use '\n' separator; the problem here is you need to read entire file content in one single big buffer and this can have negative effects depending on file size.

 

Additionally, I seem to remember you cannot nest two independent strtok (one to scan lines in file and the second to scan field in every line) in a single flow.



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 6 of 11
(4,645 Views)

sir Roberto as in case of read line when we give in argument -1 it read the line till the complete line.

ir redafile we have to give maximum bytes in argument to read number of bytes. is there any argument or way whic reads the whole file in one buffer because we dnt know the number of bytes to read

0 Kudos
Message 7 of 11
(4,640 Views)

khadimhussain ha scritto:

(...) because we dnt know the number of bytes to read


you know it



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 8 of 11
(4,631 Views)

sir roberto which argument we will use in read file to read the whole file. in read line we give -1 to read whole line

0 Kudos
Message 9 of 11
(4,622 Views)

Have you noted the link in my previous answer? It points you to where I listed some functions that return the file size, which is the value you must pass to ReadFile to fully read it.



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 10 of 11
(4,609 Views)