your site's 'house solutions' need some serious QA. e.g. 7-1:
while ((c = getchar()) != EOF)
if (strcmp(name, "lower") == 0)
putchar(tolower(c));
else if (strcmp(name, "upper") == 0)
putchar(toupper(c));
else
putchar(c);
the two strcmps are executed for each input char. this is unnecessary and abysmal. once before the main loop is enough, as name never changes. this is the only exercise i tried, but it instantly makes me think there must be other horrors lurking.
Wow, this is pretty cool! I'm a bit beyond working through K&R exercises, but I appreciate the effort this took, and it is a great resource for new learners.
It literally says for this program "Exited with code 13; main must return 0. Your output was correct; only the exit failed the test."
puts returns non-negative on success, glibc returns number of characters written.
You tried to be cute 1337 hax0rz with your return puts (in a very old and portable language with like 5+ standard library implementations) and then go "Seriously?" at a site that even gave you direct error reason and told you they use GCC so you can take a guess what libc it uses.
I think for this particular case, printf() is not the most appropriate. The output is really not formatted and the output requires a \n that is free in puts(). printf() would be scanning the string looking for format specifiers only to find none. puts() won't have to do any of that.
That's just my preference. I'm sure others will find their own reasons to use printf() in this particular case.
At first I thought you really didn't understand what happened, but based on your behavior I'm now 99% sure you knew it'd check the return code (as many/most/all online judges do) and you wrote this convoluted return puts to then come here and put OP down and act all smart and arrogant as if you found a real problem in their website. Absolutely gross behavior.
You're wrong, puts on glibc returns count of characters written so he gets "Exited with code 13; main must return 0. Your output was correct; only the exit failed the test."
There is also no requirement for you to be a smarmy redditor yet here we are. It literally told you: "Exited with code 13; main must return 0" and it's a completely normal feature of online judges and normal practice in real life programming to verify process exit codes.
1
u/thondat 3d ago
your site's 'house solutions' need some serious QA. e.g. 7-1:
the two strcmps are executed for each input char. this is unnecessary and abysmal. once before the main loop is enough, as name never changes. this is the only exercise i tried, but it instantly makes me think there must be other horrors lurking.
1
u/johntrytle 4d ago
Damn this would've been super useful when I was using that book
1
u/BigLeagueChew4u 4d ago
very cool
1
u/Automatic-Tackle5018 4d ago
Wow, this is pretty cool! I'm a bit beyond working through K&R exercises, but I appreciate the effort this took, and it is a great resource for new learners.
0
u/sciencekm 3d ago
I did this one:
and submitted:
It was declared "failed." Seriously?