Hello..
Im making a code for processing a data that contains \r\n or just \n at the end of each line. Heres what I have written so far:
Code:
char *tmp, *temp, *ptr;
tmp = new char[1024];
sprintf(tmp, "line 1\r\nline 2\r\nline 3\n");
printf(tmp);
temp = tmp;
while (1) {
ptr = temp;
temp = strchr(ptr, '\n');
if (temp)
*(temp++) = 0;
else
break;
//something missing
printf("line: %s\n", ptr);
}
this will print:
line 1\r
line 2\r
line 3
Now the problem is I dont know how to check if the last character/letter in the line is \r set it the *pointer to 0.
What would be the best way to do this?
Thanks a lot for help