text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
And if that's the case, I'm
going to arbitrarily return 1. | 439.65 | 2.48 |
So recall that main can return values. | 442.13 | 2.12 |
0 means all is well. | 444.25 | 1.2 |
1 or any other non-zero value
means something is wrong. | 445.45 | 2.6 |
So maybe that's what I was doing wrong
earlier, just not error checking. | 448.05 | 3 |
So let's try that. | 451.05 | 1.04 |
Now, let me declare a variable of type
string called t and assign it to s. | 452.09 | 5.94 |
So in other words, I
want to copy s into t. | 458.03 | 3.09 |
And I know that this happens
from the right to the left. | 461.12 | 2.35 |
So that's as I think it should be. | 463.47 | 2.41 |
And then, if strleng of
t is greater than 0-- | 465.88 | 7.302 |
you know what, I'm going
to do one other thing. | 473.182 | 1.958 |
Not just copy it. | 475.14 | 0.924 |
I'm going to go ahead and do this. | 476.064 | 1.416 |
Recall, that you can
treat strings as arrays. | 477.48 | 2.02 |
So I'm going to say the zeroth
character, the first character of t-- | 479.5 | 3.477 |
you know what? | 482.977 | 0.583 |
I want to uppercase it. | 483.56 | 1.61 |
I want to really make sure that
these two strings are indeed | 485.17 | 2.79 |
different as I intend. | 487.96 | 1.58 |
And let's go ahead now and do this. | 489.54 | 3.3 |
Let me go ahead now and do printf of s. | 492.84 | 4.5 |
And let me plug-in s's
value in a new line. | 497.34 | 2.18 |
Plug-in s. | 499.52 | 0.7 |
And then printf t:%s
for a placeholder again. | 500.22 | 4.87 |
Comma t semi-colon. | 505.09 | 1.74 |
So in other words, if the length
of t is greater than zero, | 506.83 | 3.69 |
let's capitalize it by
changing that first character. | 510.52 | 2.764 |
And then, just print out s and t. | 513.284 | 1.375 |
And surely, by capitalizing only t, I
should see only one capitalized word. | 514.659 | 5.091 |
Now, I'm using both
strleng and two upper. | 519.75 | 1.812 |
So rather than let Clang have a chance
to yell at me, I'm going to go in here | 521.562 | 3.208 |
and preemptively add ctype.h. | 524.77 | 3.056 |
Which recall is a library
you might have seen | 527.826 | 1.874 |
or certainly will soon see that
has a number of functions in it. | 529.7 | 3.34 |
Among them, two upper. | 533.04 | 1.18 |
And then, I also need to include
string.h, so that I can use strlen-- | 534.22 | 4.094 |
the function that gives me
the length of the string. | 538.314 | 2.166 |
So Clang would have yelled at me if I
forgot that, but let me preemptively | 540.48 | 2.89 |
solve that problem. | 543.37 | 0.82 |
And now, do make copies zero. | 544.19 | 2.35 |
All seems to be well. | 546.54 | 1.03 |
Let's run dot slash copy 0. | 547.57 | 1.861 |
All right. | 549.431 | 0.499 |
Let's go ahead and type in-- how about
just my own name in all lowercase. | 549.93 | 6.05 |
Huh? | 555.98 | 1.31 |
Now, why is this confusing? | 557.29 | 2.04 |
So I wrote code that got a string
from the user and stored it in s. | 559.33 | 5.53 |
I then wrote code that
declared a second variable, t. | 564.86 | 3.48 |
And I set t equal to s,
thereby making I would | 568.34 | 2.88 |
think a copy-- as in past weeks
of using the assignment operator. | 571.22 | 3.7 |
Then down here, I made
sure t was long enough. | 574.92 | 2.21 |
That's just a quick sanity check. | 577.13 | 1.71 |
And then on this line
here, I'm just saying, | 578.84 | 3.18 |
set the first character of t, t bracket
0, equal to the result of upper casing | 582.02 | 5.85 |
the first character of t. | 587.87 | 2.13 |
So the only code that's
touching t is this one here. | 590 | 3.37 |
And yet, somehow my name gets
capitalized both in s and in t. | 593.37 | 5.38 |
So what is it that's
actually going on here? | 598.75 | 3.67 |
It seems to be broken still. | 602.42 | 2.559 |
In fact, let me go ahead and open
another example, rather than type | 604.979 | 2.791 |
this one out ourselves. | 607.77 | 1.73 |
Let me go ahead and open up
an example called no swap. | 609.5 | 4.42 |
As the name suggests,
it's a bit of a spoiler. | 613.92 | 2.59 |
I wrote this program in
advance to do the following. | 616.51 | 2.82 |
First, I've included standard
io.h, so I can use printf. | 619.33 | 3.61 |
I have a prototype of my function
called swap up here, because indeed, | 622.94 | 3.55 |
the goal at hand I decided was I just
want to write a simple function that | 626.49 | 4.11 |
swaps two values. | 630.6 | 1.69 |
Given a and b, make b a and a, b. | 632.29 | 2.86 |
And then, return. | 635.15 | 0.99 |
So I'm just going to arbitrarily test
this out by declaring a variable x. | 636.14 | 3.06 |
Setting it equal to 1. | 639.2 | 1.17 |
A variable y setting it equal to 2. | 640.37 | 2.35 |
And then, just as a sanity check, I'm
going to print out x is such and such, | 642.72 | 3.3 |
y is such and such. | 646.02 | 1.18 |
And then, I'm going to
claim swapping dot dot dot. | 647.2 | 2.92 |
And then, the key line
is apparently this one. | 650.12 | 2.68 |
Call a function called
swap, passing in x and y. | 652.8 | 3.51 |
And if I implemented swap correctly,
this should swap the two variables. | 656.31 | 4.09 |
Thereafter, I'm going to claim swapped
x as such and such, y as such and such. | 660.4 | 4.69 |
So let's run this program and see
what else is apparently a lie. | 665.09 | 5.19 |
Make no swap in my source directory. | 670.28 | 6.62 |
./noswap enter. | 676.9 | 3.71 |
And if we scroll back up in my
history, you'll see x is 1, y is 2. | 680.61 | 4.95 |
Swapping swapped. | 685.56 | 1.66 |
x is 1, y is 2. | 687.22 | 1.431 |
All right. | 688.651 | 0.499 |
So maybe just the swap
function is buggy. | 689.15 | 1.96 |
This isn't necessarily
indicative of a misunderstanding. | 691.11 | 3.17 |
So let's look at the
implementation of swap. | 694.28 | 2.01 |
Swap returns no value and I think
that's OK, so long as it takes inputs. | 696.29 | 4.5 |
Swap takes two inputs, an ints and
an ints, called a and b respectively. | 700.79 | 4.64 |
And then, let's consider how this works. | 705.43 | 1.72 |
So I've declared a temporary
variable, called temp-- | 707.15 | 3.225 |
though I could call it anything I want. | 710.375 | 1.625 |
And I'm storing in it the value a. | 712 | 2.28 |
So I'm taking a-- and it's the number 1. | 714.28 | 1.975 |
And I'm just temporarily
storing the number 1 | 716.255 | 1.875 |
in this additional temporary
variable, so that I now | 718.13 | 2.22 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.