I'm having trouble parsing a simple iCalendar file in C.
char * description, * identifier, *tofree;
tofree = description = strdup(string);
identifier = strsep(&description, ":");
printf("{%s}\n", identifier);
printf("[%s]\n", description);
free(tofree);
{BEGIN}
]VCALENDAR
Your input data ends with a carriage return, \r
. Your code outputs:
[VCALENDAR\r]\n
and the carriage return places the cursor at the start of the line so the ]
overwrites your [
.
It's probably best to remove the line ending before scanning; failing that, include \r
and \n
in the delimiters provided to strsep()
, but you'd have to use strsep()
a second time to get the VCALENDAR
token.