View Single Post
Old 15/02/2018, 03:15 PM   #4
Little Clucker
Join Date: Jul 2013
Posts: 18
Reputation: 0
Default Re: Anyone have some feedback? (C code)

Originally Posted by yugecin View Post
Does it also works for whitespace that's not at the beginning of a line?

Like if you have
abcd    efg
I think the 4 spaced should be replaced by a tab when tabsize is 8 or 4 (or 2 tabs when tabsize is 2). I can't test right now but I think your code does not handle that (if that's in the scope of the exercise).

I'm not very experienced in c, but I guess I would write it somewhat the same. I would just avoid else and use continue in most cases, but that's just a personal preference.

You may want to try out code review on stack exchange, it's a place where people can show their code and other people can review it. You may not get full solutions in a different way, but you will probably get some nice feedback (more than you'll get here).
That case works, the code handles it in the way that it counts all non-whitespace characters and evaluates the gap based on the tabsize we defined on the top of the file - that number of non-whitespace chars, specifically this line:

if(ns >= TABSIZE - nc)
For the comment of avoid else and use continue, i assume you mean the else inside the while loop that evaluates whether one or more spaces are still "in buffer". Wouldn't using continue not allow me to put that space and decrease the space count, while the else does? Is it too much to ask if you can rewrite this with your continue method so that I can see how you'd do it?

Thanks for the reference to the site too, I'll definitely use it.

Originally Posted by Sew_Sumi View Post
I like the over-documentation...
I like the sarcasm All joking aside, the comments are there because I posted the same code on a thread (on stackexchange) where people were solving the problem also. I agree that for production code there should be documentation like this, but perhaps separate from the source code or else it would be 100000 lines of comments per source :P
Paglia is offline   Reply With Quote