Am I OCD when I cringe when I see 'p_rite' where he (I think) means 'p_write'? That alone would knock a few points off a candidate doing this test when he's interviewing with me. 'rite' can mean 'write' or 'right' or even 'allright' - why the unnecessary confusion?
You're not alone in feeling the OCD twinge, but are almost certainly alone in being willing to demerit a candidate writing that.
Interviewing programmers: coding test example explained
31–40 of 178 posts
Re: Interviewing programmers: coding test example explained
#32So when do we get to read part 3? I want to see what "creative" solutions people came up with.
Currently working on that. It's safe to say that your two solutions were the most creative. In my graph of solution proximity, they are both a long way away from all the other solutions.
Re: Interviewing programmers: coding test example explained
#33'\0' is null-terminated NOT zero-terminated, no ? By definition, a string in C is always null-terminated.
Also, C strings are NUL-terminated, not NULL-terminated. (char)(0) is the NUL character; (void * )(0) is the NULL pointer (usually).
Re: Interviewing programmers: coding test example explained
#34Am I OCD when I cringe when I see 'p_rite' where he (I think) means 'p_write'? That alone would knock a few points off a candidate doing this test when he's interviewing with me. 'rite' can mean 'write' or 'right' or even 'allright' - why the unnecessary confusion?
Re: Interviewing programmers: coding test example explained
#35'\0' is null-terminated NOT zero-terminated, no ? By definition, a string in C is always null-terminated.
Re: Interviewing programmers: coding test example explained
#36Earlier quoted context omitted.
You're not alone in feeling the OCD twinge, but are almost certainly alone in being willing to demerit a candidate writing that.
Why would he be alone? Why is spelling less important in code than in normal writing? I would argue it is considerably more important.
In the industry I work in --- computer software --- it is ludicrously hard to find people competant in C programming, and I'm inclined to ignore idiosyncratic spelling in source code.
Re: Interviewing programmers: coding test example explained
#37 #define C char
#define F for
#define R condense_by_removing
#define V void
V R(C*A,C B){F(C*J=A;*J=*A++;J+=*J!=B);}
or without #defines: void condense_by_removing(char*A,char B){for(char*J=A;*J=*A++;J+=*J!=B);}Re: Interviewing programmers: coding test example explained
#38hmm, is it normal to assume all strings in C are \0 terminated? What are the memory usage implications for that? I won't pretend to know C but suppose you have a string that is 'ab{100}\0' and you wanted to remove all of the bs, you'd end up with 'a\0b{99}\0' in memory correct?
Yes, C strings are \0 terminated and that is what you'd end up with. Memory management is between you, malloc() and free(). Assuming this were malloc()d memory, if you wanted to free up the unused bytes, you'd probably: char *condensed = strdup(z_terminated); if (condensed) free(z_terminated); else // out of memory
Re: Interviewing programmers: coding test example explained
#39I'm sure RiderOfGiraffes doesn't want a third entry from me at this point, so I figure I might as well just post it here: #define C char #define F for #define R condense_by_removing #define V void V R(C*A,C B){F(C*J=A;*J=*A++;J+=*J!=B);} or without #defines: void condense_by_removing(char*A,char B){for(char*J=A;*J=*A++;J+=*J!=B);}
Re: Interviewing programmers: coding test example explained
#40'\0' is null-terminated NOT zero-terminated, no ? By definition, a string in C is always null-terminated.
char c = 65
is equivalent to and just as legal as char c = 'A'
So yes, C strings ARE zero-terminated. In fact, it is a bit weird to say they are null-terminated. It is technically true, given that NULL often translates to 0, but NULL is a pointer value in the same way that zero is a number.For some reason, I vaguely remember some security hack in one OS where NULL went to a special place in memory that was marked as invalid (1, 63, or something), so in that case, NULL was not defined as 0. Since the memory is vague, though, don't quote me on it.