问题描述
我需要解析 CSV文件 [ ^ ].
我的文件数据采用以下格式,
NRTIT15; 15/05/2005;
NRTIT16; 16/06/2005;
OZ9520; 03/09/2004;
我需要检查EOF文件中的空白行.
如果我的文件末尾包含换行符,我想打印错误消息.
对于每一行,我使用\ n.但我想在EOF上检查换行.
我的解析函数是
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,
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;
}
如何检查文件中的空格/制表符/CR/LF?
在此先感谢.
这是第21个问题,您仍在等待其他编辑器格式化源代码.请打好.
How can I check the space/tab/CR/LF in my file?
thanks in advance.
This is the 21th question and you still waiting for other editors to format your source code. Please play nice.
推荐答案
while(pLine [i]&& pLine [i]!=''''&& pLine [i ]!=''\ t''&&
pLine [i]!='';''&& pLine [i]!=``#'')
{i ++; }
while (pLine[i] && pLine[i] != '' '' && pLine[i] != ''\t'' &&
pLine[i] != '';'' && pLine[i] != ''#'')
{ i++; }
会变成
would become
while (pLine[i] && pLine[i] != ' ' && pLine[i] != '\t' &&
pLine[i] != ';' && pLine[i] != '#')
{
if ( pLine[i] == '\n') return 0;
i++;
}
:)
:)
这篇关于用C解析文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!