Timeline for Print a sinusoidal wave (vertically)
Current License: CC BY-SA 3.0
19 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jan 19, 2014 at 15:20 | comment | added | treamur | @ugoren, brilliant ideas again, thanks! I added them to the answer. | |
Jan 19, 2014 at 15:19 | history | edited | treamur | CC BY-SA 3.0 |
added 51 characters in body
|
Jan 19, 2014 at 9:33 | comment | added | ugoren |
@treamur - Two ugly ideas - 1. Omit ! (with 0 FDs, poll doesn't use the pointer). 2. Use %*c| with 0 (prints invisible NUL characters).
|
|
Jan 19, 2014 at 8:50 | comment | added | treamur | @ugoren, totally so! Thank you for the tip. :) | |
Jan 19, 2014 at 8:49 | history | edited | treamur | CC BY-SA 3.0 |
Changed from while loop to recursive main()
|
Jan 19, 2014 at 8:04 | comment | added | ugoren |
main(poll(!printf(...),0,50)); saves a character.
|
|
Jan 17, 2014 at 11:39 | comment | added | treamur | @Art, totally awesome, thanks! Implemented both of your ideas. I had been thinking of poll() myself, but I mistakenly landed my eyes on ppoll() parameter list on the manual page, so I discarded the idea. I was too hasty. Very nice that you brought the idea up again. :) | |
Jan 17, 2014 at 11:35 | history | edited | treamur | CC BY-SA 3.0 |
added 11 characters in body
|
Jan 17, 2014 at 11:31 | comment | added | primo |
"%*s" , where have you been all my life? +1 just for that.
|
|
Jan 17, 2014 at 10:24 | comment | added | Art |
One more character by replacing usleep(50000); with poll(0,0,50); .
|
|
Jan 17, 2014 at 10:17 | comment | added | Art |
You can cut out two more characters by moving the assignment to j into the printf, like this: printf("%*s\n",j=21+sin(i++*.1)*20,"|") . The resulting type is still int so it's a valid field width argument.
|
|
Jan 17, 2014 at 9:31 | comment | added | musiphil | @treamur: Thanks for the info. I also considered the possibility of a type error, but pre-ISO C was so archaic that I couldn't figure out the rules exactly. :) | |
Jan 17, 2014 at 5:33 | comment | added | treamur | @moala, thanks! Using *.1 instead of /10 seems to work. | |
Jan 17, 2014 at 5:32 | comment | added | treamur |
@musiphil, I also thought about using 5E4, but it turns out that it does not work: Without showing the compiler usleep() prototype, you would have to explicitly cast the 5E4.
|
|
Jan 17, 2014 at 5:30 | history | edited | treamur | CC BY-SA 3.0 |
added 13 characters in body
|
Jan 17, 2014 at 1:58 | comment | added | moala | I think you could use *.1 instead of /10. | |
Jan 17, 2014 at 0:00 | comment | added | musiphil |
I think you could use 5E4 instead of 50000 .
|
|
Jan 16, 2014 at 21:41 | comment | added | treamur | This was inspired by @ace's own C answer. | |
Jan 16, 2014 at 21:40 | history | answered | treamur | CC BY-SA 3.0 |