Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I need to parse a CSV file[^].
My file data is in below format,
NRTIT15;15/05/2005;
NRTIT16;16/06/2005;
OZ9520;03/09/2004;

I need to check the blank lines in the file at EOF.
If my file contains line feed at the end, i want to print the error mesasge.
For each line i am using \n. but i want to check for new lines at the EOF.
My parse function is,
C++
int SRR_parseLine(char * pLine,
                  int  * pLenName,
                  int  * pPosValue,
                  int  * pLenValue)
{
  int  i                              = 0;  
 
  while (pLine[i] && pLine[i] != ' ' && pLine[i] != '\t' &&
         pLine[i] != ';' && pLine[i] != '#')
  {    i++;  }
  if (i == 0)
  {
    return 0;
  }
  *pLenName = i;
  while (pLine[i] && (pLine[i] == ' ' || pLine[i] == '\t'))
  {    i++;  }
  if (pLine[i++] != ';')
  {
   return 0;
  }
  while (pLine[i] && (pLine[i] == ' ' || pLine[i] == '\t'))
  {    i++;  }
  *pPosValue = i++;
  while (pLine[i] && pLine[i] != '\n'&& pLine[i] != '"')
  {    i++;  }
  *pLenValue = i - *pPosValue;
  return 1;
}

How can I check the space/tab/CR/LF in my file?

thanks in advance.

EDIT: This is the 21th question and you still waiting for other editors to format your source code. Please play nice.
Posted
Updated 2-Jun-10 22:48pm
v8
Comments
Sandeep Mewara 3-Jun-10 1:19am    
Pre tags are your friend for formatting the code part, use it next time!

You should check the end of line condition in every loop, for instance:

Poonamol wrote:
while (pLine[i] && pLine[i] != ' ' && pLine[i] != '\t' &&
pLine[i] != ';' && pLine[i] != '#')
{ i++; }


would become

C#
while (pLine[i] && pLine[i] != ' ' && pLine[i] != '\t' &&
         pLine[i] != ';' && pLine[i] != '#')
  {
    if ( pLine[i] == '\n') return 0;
    i++;  
  }


:)
 
Share this answer
 
Comments
Nish Nishant 13-Jul-10 11:14am    
Reason for my vote of 5
Worth 5!
Thank you so much for the reply.
I know the data limit for each line.
So if strlen(pLine) is less than limit or greater than limit then I am printing error.
It works fine for me. :-O
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900