« first day (38 days earlier)      last day (147 days later) » 
02:00 - 04:0004:00 - 06:00

2:53 AM
@moshe
 
@stdOrgnlDave Hi, I'm here.
 
hello
what is your homework assignment
 
@stdOrgnlDave Implementing a C string class, as described here. (link)
 
what is the documentation you are using for each function you're re-implementing
like, to know what its purpose is
 
Well, I just poked at cplusplus.com, that's what the professor showed us.
I actually realized that my Mac has man pages for those functions too...
 
2:56 AM
OK, what do you know about c strings
 
I know they're arrays of chars.
Arrays are just pointers
 
stop there
arrays aren't just pointers
 
stopped.
 
arrays decay into pointers. that's not a point that's important right now, but you must remember it for the future
you can treat them conceptually the same for now
so yes, they're arrays of pointers
 
Ah, ok.
 
2:58 AM
I mean
arrays of chars
sorry it's late @johnathon will help
so, how do you know when you reach the end of a c string?
 
myCString.length(), no?
Oh, the null terminator.
@BraniRobinCohen - Still there?
 
moshe what are you doing
 
the null character
 
oh damnit
 
but , i have problems with that, because it all depends on what allocates the c string
 
3:00 AM
I'm so tired, yes, the null terminator
@johnathon this is basic stuff, don't worry about that yet
 
ok
so nothing over k&r c right?
 
@Moshe if I have a string "hello" how many bytes do I need to store it?
@johnathon not atm :-P
 
@johnathon stop answering for him you're supposed to help not be a jerk :-P
I'm trying to figure out his level of knowledge
 
@stdOrgnlDave 6
 
3:01 AM
ah
 
OK. so, let's do strlen because that's one of the easiest
paste your code
 
ok
int mycstring::mystrlen (const char *str){
if(str=="") return 0;
else {
count++;
return count+mystrlen(str);
}
}
 
why are you doing this: if(str=="") return 0;
what I mean is, please explain your intent
 
Hrm, Ok, so actually, I'm about to look really dumb.
I'm working with @BraniRobinCohen on this. Not actually my code. But I'm the StackOverflow user.
 
it's ok, let your ignorance out so we can replace it with knowledge :-P
?
 
3:03 AM
But I'm not sure what the intent was, and I could use a good learnin' myself.
I suppose the intent was to check for a null string
 
the intent was to check for the null terminating character
unfortunately it was done wrong
 
Ah, I see.
Yea, so how about
 
first of all, the expression str evaluates to a number, more or less. it is a pointer
 
@Moshe "" indicates an array of characters, and does not look at the individual characters, '' does
 
if(*str =='0')
 
3:05 AM
close
 
asying str == "" is asking if str is pointing to the string literal "" you just made up
 
Is that better?
 
close
if(*str==0)
 
*str == '\0'
 
either way
 
3:05 AM
Ah, makes sense.
 
that dereferences the pointer, meaning you're evaluating the data it's pointing at, not the pointer itself
 
Ok.
 
does he understand pointers to begin with?
 
I believe so.
We covered it in class.
 
describe to me what a pointer is
 
3:06 AM
OK, where is 'count' declared?
actually, do what @johnathon said
 
A pointer holds a memory address of a value.
 
Kinda... but elaborate
because it does more than just store the memory address
 
A pointer is of a given type. It holds the integer value of a memory address at which the computer is storing an object of a said type.
 
there ya go
 
OK :-P
so where is 'count' declared?
 
3:09 AM
the importance of this is, that when you derefernce a pointer , it knows how much beyond the start of the memmory address it's point to to look at to represent the type of the object it's pointing to
 
Ok
right, we covered that in class.
@stdOrgnlDave Count, as in our code?
Well it's not, heh.
Should've noticed.
 
you're using a C compiler then
 
Well, g++ on Mac OS X
 
it implicitly declares it as an int when it is used there
 
The compiler choked sooner.
 
3:11 AM
um, clang on mac osx
 
I think the latest iOS SDK uses LLVM, is that clang?
 
all you need to do is return mystrlen(str)+1
 
yes, llvm is clang
 
what kind of function is this? other than a function to determine the length of a string
there's a name for the type of function it is
 
a member function
 
3:12 AM
ok wait, is this learning C , or learning C++ ?
 
C++
 
im now confused, because the c lib has a strlen() function just for this case
ah
continue
 
but what kind of control flow is it?
 
recursive
 
OK good
 
3:14 AM
@johnathon HW:
 
so now paste correct version with what we've learned
 
19 mins ago, by Moshe
@stdOrgnlDave Implementing a C string class, as described here. (link)
 
ok.
 
int mycstring::mystrlen (const char *str){
if(*str ==0) return NULL;
return mystrlen(str+1);
}
B, you here?
 
return 0
 
3:15 AM
cringes @ NULL
 
instead of NULL
 
Whoops
 
ummm
also there's a problem with the return statement
 
?
 
well, what value will it return if it recurses 5 times?
 
3:17 AM
the lovely + 1 issue
 
Hrm.. Runs 5 times.
mystrln("hello"); -> mystrln("ello") -> mystrln("llo") -> mystrln("lo") -> mystrln("o") -> mystrln("")
6
No?
 
no, it'll return 0
 
Oh, that's right.
 
because it just returns its own value until it reaches the end, when it returns 0
 
Professor mentioned this...
I forgot what he said.
 
3:19 AM
static variable.
 
dur
 
@johnathon no
 
not a static function
overlook me at times :))
 
@moshe you want to increment what is being returned. at the very end you don't return anything because it's a null character
 
3:20 AM
@stdOrgnlDave Rings a bell, how do you do use a static variable here?
 
but up until then, every time you recurse you're doing it because one character has passed the check (not 0)
don't use a static function here
 
i said overlook me
 
Heh, my mistake
 
scratch that idea from your head
 
return mystrlen(str+1) + 1;
 
3:21 AM
Ok, done
 
do you understand why?
 
Yea, we won't reach the extra +1 if the initial string is 0 in length, but otherwise we do, so add it at the very end.
 
so as we walk over the string hello
h - passes, return next +1
 
right, got it
 
e - passes, return next + 1
l - passes, return next + 1
l - passes, return next + 1
o - passes, return next + 1
(0) - fails, return 0
as you see it sort of "adds up" (pardon the pun)
 
3:23 AM
Yea, gotcha.
 
OK :-P so paste correct code
 
:3659936     int mycstring::mystrlen (const char *str){
            if(*str ==0) return 0;
            return mystrlen(str+1)+1;
    }
 
good, you stripped out the unnecessary else
 
Ok, got that.
 
alright, let's move onto another one, and this should help you with all the others - strcpy
 
3:26 AM
(removed)
Ok, let's go.
 
what do you have currently?
 
char* mycstring::mystrcopy(char *dest, const char *src){
*dest=*src;
return dest;
}
 
what is the intent of *dest = *src;
 
@stdOrgnlDave Looks like a shallow copy.
But probably should be a deep copy.
 
indeed.
it'll copy the first byte
so how do you do a deep copy
if you don't know go ahead and say...I'm here to help
 
3:31 AM
bit*
Is that the while(*dest==*src) but?
 
hmm, no, that's for comparing a string
 
tip: build off your previously established functaionality
 
while(strln(str1)>0){
um, no, feels wrong
I need to allocate memory for the string, right?
 
no, that is allocated for you
I mean, that's how the C standard library does it
I didn't see your professor say anything different
 
Well, if we're rewriting the function, we need to create the memory, no?
 
3:35 AM
traditionally when you use strcpy() you already have the buffer that is to receive a copy of the string allocated
 
Oh, ok.
 
so you don't need to worry about that right now
 
I'll take a free buffer any day.
 
you just need to make sure that all the bytes from *src (including the NULL terminator) get into *dest
 
Ah, ok.
I remember we dealt with this too..
I'm an idiot for not taking these notes when he wrote them on the board.
 
3:37 AM
well, take a guess
take a concrete example
you have hello0
(0 represents terminator)
and a 6-byte empty buffer
 
right,
ok
I'm trying to think of the recursive solution
 
it wouldn't be too different from the strlen one
 
Hum...
int mycstring::mystrlen (const char *str){
if(*str ==0) return 0;
return mystrlen(str+1)+1;
}
int mycstring::strcopy(const char* src, const char *dest){ if(*str == 0) *dest == 0; *dest = =*str; return strcopy(str+1);}
 
that's moving in the right direction
 
dear god he's got your 1 line style
 
3:43 AM
oh stuff it @johnathon that's just for being nasty to geordi
 
No, it's the chat box.
I'm gonna rewrite in vim in a sec
 
OK :-P
two questions to ask yourself: how does that know how to terminate? and also, shouldn't it be passing 2 arguments back to itself (since it takes two)?
 
char* mycstring::mystrcopy(char *dest, const char *src){
if(*str == 0){
*dest == 0;
return dest;
}

*dest = =*str;
return strcopy(str+1)

}
Well, how's that?
 
getting much closer
what is the intent behind using 2 ='s
 
Whoops
@stdOrgnlDave To teach myself to not write one line functions, so I can actually read them. :P
char* mycstring::mystrcopy(char *dest, const char *src){
if(*str == 0){
*dest = 0;
return dest;
}

*dest = *str;
return strcopy(str+1)

}
 
3:46 AM
*dest = =*str;
?
 
Whoops
Better?
 
yes, except of course it is src not str
ok, now there's only one problem left, and that is with the recursive call. the function takes 2 parameters not 1
 
So cat I got, I think.
Ah, right, pass in the entire dest, or increment that too?
I think increment.
 
yep
gotta increment both
 
Cool
 
3:48 AM
there'll still be one last flaw with this though :-(
 
Hum
 
it is supposed to return, at the end, the original dest passed into it
 
And the pointer keeps moving.
So it'll only return the single character at the end.
 
@stdOrgnlDave return strcopy()-1?
 
3:50 AM
actually,
hm.
would that work? never thought of that :-P
 
What were you going to suggest?
 
an operator overload
I think that might work, I'm a bit too tired to be sure
 
Naw, that's overcomplicating it.
I'm going with -1
 
yeah, that seems logically correct in my tired state
there'll be the same number of decrements as increments
alright what do you want to move on to next
 
Hrm...
@stdOrgnlDave mystrcat
char* mycstring::mystrcat(char *dest, const char *src){
*dest+=*src;
return dest;
}
 
3:54 AM
?
 
Is what we have.
concatenate 2 strings
 
this is going to be an interesting one
 
think through what *dest+=*src will do
 
I would modify copy, but can I assume enough space here as well, or must I allovte.
 
allocate
 
3:55 AM
Just add the values of the ASCII characters at the pointer destinations.
 
@johnathon no allocate! :-P read the damn reference
@moshe yep
 
So you have two random characters being added for potential garbage
 
@moshe to cat, first we have to find the first null terminator in dest
 
Ah, Joel @Spolsky discusses this in his book/blog.
 
making this one recursive is a bit more difficult than the others
 
3:56 AM
sighs i keep having to remember , C functions
 
Is this the one professor called programming pr0n?
Don't remember.
He def used the term for one of them.
 
your professor called it programming porn?
 
:))
 
what college do you go to?
 
for real.
 
3:57 AM
cuny.brooklyn.edu
He wasn't serious, was joking.
 
no, it's just funny
 
Okay, Joel's website (link) has strcat defined as this:
char* mystrcat( char* dest, char* src )
{
while (*dest) dest++;
while (*dest++ = *src++);
return --dest;
}
 
would you like to know why that works?
 
Actually, that is what the professor called programming porn.
 
3:59 AM
Yea, I would.
 
well, you know what a while loop is right?
I don't mean to sound condescending
 
02:00 - 04:0004:00 - 06:00

« first day (38 days earlier)      last day (147 days later) »