LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Read in a multiline csv file in Labwindows/CVI

Hi,
 
  My csv file is formatted as such:
<----------------------->
AID,partNumber,HardwareRevision
 
NHFH0A0165002050603333,68-0165-002,A
<----------------------->
 
  I can read the first line in fine and split the csv string, but I am unable to read in the second third line (second line is blank space).  I have tried "While (!feof(fptr))" with no luck, goes into a continious loop and still only reads the first line.
  Any help would be greatly appreciated.  Thanks.
 
Chaz Byrne
 
 
  My current code:
<----------------------->
#include <formatio.h>
#include <userint.h>
#include <ansi_c.h>
int main()
{
 
 FILE *fptr; //file pointer
 char string[2000];  
 char item1[50];
 char item2[50];
 char item3[50];
 
    if ( (fptr = fopen( "C:\\AID.csv", "rt"))==NULL )
    { 
     printf("Warning: Problem opening file or file not found\n");
        return -1;
    }
    fscanf(fptr, "%s", string);
    
     //while (feof( fptr)==0)
     //{
      Scan (string, "%s[xt44]%s[xt44]%s[xt44]", item1,item2,item3);
      printf("%s\n%s\n%s\n%s\n\n",string,item1,item2,item3);
    //}
    fclose( fptr );
    MessagePopup ( "Just to hold it...","Testing");
 return 0;
}
<----------------------->
 
Output:
<----------------------->
AID,partNumber,HardwareRevision
AID
partNumber
HardwareRevision
<----------------------->
0 Kudos
Message 1 of 2
(4,248 Views)
fscanf(fptr, "%s", string); is what reads a line from your file into the string variable.  Scan() only parses the string for you.  You need to move the fscanf() call into your while loop to get a new line for each iteration.

Message Edited by mvr on 03-02-2006 02:13 PM

0 Kudos
Message 2 of 2
(4,248 Views)