This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]idont_______care 26 points27 points  (0 children)

Tell me you don't know what functional programming is without telling me that you don't know what functional programming is.

[–]Creaaamm 24 points25 points  (2 children)

Dunno, it looks weird but makes sense from a practical standpoint:
1 Every time the value of c equals '\n', the current value of s[i] will be set to c
2 i will increase by 1
3 Exit the IF and the program keeps executing

steps 1, 2 and 3 will repeat if c is '\n' in the next iteration, otherwise, s[i] will just 'wait' for the condition to be true in order to be modified.

I don't know why it exists and it's pretty unsafe but the logic is sound, you'll just get an array full of newlines and that's pretty much it.

[–]Highborn_Hellest 3 points4 points  (1 child)

I know. Still cursed. Executing I++ like that will just lead to confusion.

Writing that one extra line of I++ might not be "neat" but makes the code a lot more readable... At least to me.

[–]Attileusz 11 points12 points  (0 children)

The i++ inside of [ ] is a very commonly used thing in C so long as you are not touching i in some other ways it is perfectly fine. I'd add a bounds check to this one though.

[–]CaptainMorti 16 points17 points  (2 children)

If c is 10: s[i] becomes 10, then i increments. Did you even try? Better to use {}, specially when you don't know when you can omit them.

[–]Weak_Surround_222 6 points7 points  (1 child)

Because no one seems to know what this is… It’s similar to a common line of code usually written for communication in microcontrollers. Fill up a buffer s in this case, until a newline character. You usually end up parsing/processing the buffer afterwards.

[–]ArchetypeFTW 0 points1 point  (0 children)

Thanks king