Finding new line in string

I am Trying to find where there is a new line in a string in order to count which line is being output.
So far I have
1
2
3
4
5
for(int i=0; i<sizeoffile; i++){
if(firststring[i] == '\n' || secondstring[i]=='\n'){
linecount++;
}
}


When I do this, it doesn't end up incrementing linecount, the if statement must not happen.

Any ideas?
Show more code.
Are you sure that the line(s) contains only "\n" and not "\r\n"? If you're using Windows then your file may contain "\r\n" (CR-LF / carriage-return, line-feed) instead, in which case your test wouldn't work.
Last edited on
I tried using \r\n but that didn't work either.
Are you sure that the line(s) contains only "\n" and not "\r\n"? If you're using Windows then your file may contain "\r\n" (CR-LF / carriage-return, line-feed) instead, in which case your test wouldn't work.


Whether there is a carriage return or not doesn't matter. \r and \n are two different characters so OP's code, since it searches for '\n', would work.

Univcplus you are looping through the file's size but are checking two strings? Can you show full code?
Yeah, you're right, of course. I should have looked at the code for more than a split second. That was careless of me!
Last edited on
Topic archived. No new replies allowed.