LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

comma separated string showing on table colum

And I cut and past that extra d into my reply without thinking anything of it.  My apologies.
It takes a little while to learn the arguments to the Scan function, and if you do not use it regularly things like this will slip by.  But Scan is an extremly powerful function that is well worth spending the time to understand.  It has provided me the solution to many parsing issues and is far more fault tolerant than the ansi scanf().
0 Kudos
Message 11 of 13
(1,327 Views)
Hi,

You could use the ANSI C function strtok() as an alternative approach which would go someting like this:

char *ptrtok = 0;
int row = 1, col = 1; // (1-based index for tables)

// repeat the following segment in a loop for each line...
pseudo -> for (each line)  
{                                
if (strlen(string) > 1)             // => if potentially valid line (optional check)
   {                           
     ptrtok = strtok(string, ",");  // look for comma delimiter in string and retrieve the first "token" up to this point (e.g. "212312")
   
     if (ptrtok)   // if delimiter was found...
        {
         SetTableCellVal (panel_name, PANEL_TABLE_NAME, MakePoint(col++, row), ptrtok);  // insert first token

         // search for remaining delimters  -> NULL will be returned when end of string is reached, hence any number of delimiters may be present...
         while ((ptrtok = strtok(NULL, ",")) != NULL) 
                    SetTableCellVal (panel_name, PANEL_TABLE_NAME, MakePoint(col++, row), ptrtok); // insert subsequent tokens
         }
    
     row++;  // increment index for next row
     col = 1;  // reset column index for new row
     }
}

This approach allows each row to have any number of filled column cells. Note that in the above example, the table cell attributes must be set to accept strings instead of numbers. However, if you want the cells to contain true numberics, simply use atoi() or atof() to first convert the retrieved ptrtok segments to intergers/floats, before subsequent insertion into table cells. You may have to add code that ensures that you have a sufficient number of rows and columns prior to insertion.

John.

0 Kudos
Message 12 of 13
(1,325 Views)

Hi Roberto / Mvr / JAH

Thanks for your great help.!!

I think "Scan" is really powerful function and a single line of code. I am going to look into it,
 
Once again thanks
 
0 Kudos
Message 13 of 13
(1,311 Views)