I need to read line by line from a string. I tried the following code but I am getting a error while there are empty lines in between and not able to find what I am doing wrong.
void ReadAllLine(char *szCont)
{
int rdl = 0; /* read length */
int len = 0; /* total length */
char szLine[512] = {};
len = strlen(szCont);
int tl = 0; /* temp len */
while(rdl < len)
{
sscanf(szCont + rdl, "%512s\r\n", szLine);
rdl += strlen(szLine) + 1;
printf("%s\n", szLine);
}
return 0;
}
Input :
#Tag01
ENTRY01
ENTRY02
#Tag02
ENTRY11
ENTRY22
#Tag03
ENTRY31
ENTRY32
Output :
#Tag01
ENTRY01
ENTRY02
#Tag02
ENTRY11
ENTRY22
#Tag03
3
ENTRY31
ENTRY32
why is the 3 getting printed here?
Note : Every line is terminated with Windows notation (\r\n) and there are no spacebars before or after any line. The input is read from a file and passed to this function.