text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
code dot slash string.
2,338.8
2.18
Ah, this is much prettier.
2,340.98
1.48
Now I actually know what the computer wants me to do, give it a name.
2,342.46
3.32
>> So I'm going to go ahead and type in Rob, enter, and hello, Rob.
2,345.78
4.24
So, realize, this is still, at the end of the day, only a nine line program.
2,350.02
3.62
But we've taken these baby steps.
2,353.64
1.45
>> We wrote one line with which we were familiar, printf, hello world.
2,355.09
3.29
Then we undid a little bit of that.
2,358.38
1.6
And we actually used get string.
2,359.98
1.58
And we tossed that value in a variable.
2,361.56
1.802
And then we went ahead and improved it further with a third line.
2,363.362
2.708
And this iterative process of writing software is truly key.
2,366.07
3.15
In CS50, and in life in general, you should generally not sit down,
2,369.22
4.2
have a program in mind, and try writing the whole damn thing all at once.
2,373.42
3.38
>> It will, inevitably, result in way more errors than we ourselves saw here.
2,376.8
4.01
Even I, to this day, constantly make other stupid mistakes,
2,380.81
3.26
are actually harder mistakes that are harder to figure out.
2,384.07
3.41
But you will make more mistakes the more lines of code you write all at once.
2,387.48
4.615
And so this practice of, write a little bit of code
2,392.095
2.125
that you're comfortable with, compile it, run it, test it more generally,
2,394.22
3.71
then move on-- so just like we kept layering and layering last week,
2,397.93
3.44
building from something very simple to something more complex,
2,401.37
2.82
do the same here.
2,404.19
1.01
Don't sit down, and try to write an entire problem.
2,405.2
3.3
Actually take these baby steps.
2,408.5
2.28
>> Now, strings aren't all that useful unto themselves.
2,410.78
4.32
We'd actually, ideally, like to have something else in our toolkit.
2,415.1
3.11
So let's actually do exactly that.
2,418.21
2.78
>> Let me go ahead now and whip up a slightly different program.
2,420.99
3.91
And we'll call this int.c, for integer.
2,424.9
3.42
I'm going to, similarly, include CS550.h.
2,428.32
2.55
I'm going to include standard IO.
2,430.87
2.19
And that's going to be pretty common in these first few days of the class.
2,433.06
3.57
>> And I'm going to ready myself with a main function.
2,436.63
2.42
And now instead of getting a string, let's go ahead and get an int.
2,439.05
4.32
Let's call it i, and call it get int, close parens, semi-colon.
2,443.37
5.915
And now let's do something with it, printf.
2,449.285
2.125
>> Let's say something like hello, backslash n, comma i.
2,451.41
4.78
So I'm pretty much mimicking what I did just a moment ago.
2,456.19
3.82
I have a placeholder here.
2,460.01
1.65
I have comma i here, because I want to plug i into that placeholder.
2,461.66
3.49
>> So let's go ahead and try compiling this program.
2,465.15
2.1
The file is called int.c.
2,467.25
2.81
So I'm going to say, make int, enter.
2,470.06
2.86
Oh my God, but no big deal, right?
2,472.92
3.5
There's a mistake.
2,476.42
0.81
>> There's a syntactic mistake here such that the program can't
2,477.23
2.58
be compiled inside int.c, line seven, character 27, error format
2,479.81
5.65
specifies type char star, whatever that is.
2,485.46
2.94
But the argument type is int.
2,488.4
1.62
>> So here, too, we're not going to-- even though today is a lot of material,
2,490.02
3.09
we're going to overwhelm you with absolutely every feature of C,
2,493.11
2.6
and programming more generally, in just these first few weeks.
2,495.71
2.36
So there's often going to be jargon with which you're not familiar.
2,498.07
2.33
And, in fact, char star is something we're going to come back to
2,500.4
2.95
in a week or two's time.
2,503.35
1.48
>> But for now, let's see if we can parse words that are familiar.
2,504.83
2.7
Formats-- so we heard format specifier, format code before.
2,507.53
3.22
That's familiar.
2,510.75
1.09
Type-- but the argument has type int.
2,511.84
2
Wait a minute, i is an int.
2,513.84
2.14
>> Maybe percent s actually has some defined meaning.
2,515.98
3.25
And, indeed, it does.
2,519.23
1
An integer, if you want printf to substitute it,
2,520.23
2.871
you actually have to use a different format specifier.
2,523.101
2.249
And you wouldn't know this unless someone told you,
2,525.35
1.54
or you had done it before.
2,526.89
1.083
But percent i is what can be commonly used
2,527.973
2.517
in printf for plugging in an integer.
2,530.49
1.75
You can also use percent d for a decimal integer.
2,532.24
2.68
But i is nice and simple here.
2,534.92
1.57
So we'll go with that.
2,536.49
1.1
>> Now let me go ahead and rerun make int, Enter.
2,537.59
3.57
That's good, no errors.
2,541.16
2.168
Dot slash int-- OK, bad user experience, because I haven't told myself
2,543.328
3.932
what to do.
2,547.26
0.5
But that's fine.
2,547.76
0.666
I'm catching on quickly.
2,548.426
1.054
>> And now let me go ahead and type in David, OK, Zamila, Rob.
2,549.48
6.78
OK, so this is a good thing.
2,556.26
1.56
This time, I'm using a function, a puzzle piece, called get int.
2,557.82
3.89
And it turns out-- and we'll see this later in the term--
2,561.71
2.52
the CS50 staff has implemented get string in such a way
2,564.23
3.5
that it will only physically get a string for you.
2,567.73
2.62
>> It has implemented get int in such a way that it will only
2,570.35
3.99
get an integer for you.
2,574.34
1.25
And if you, the human, don't cooperate, it's
2,575.59
2.24
literally just going to say retry, retry, retry,
2,577.83
2.76
literally sitting there looping, until you oblige with some magical number,
2,580.59
4.61
like 50, and hello 50.
2,585.2
2.47
>> Or if we run this again and type in 42, hello 42.
2,587.67
3.77
And so the get int function inside of that puzzle piece
2,591.44
4.31
is enough logic, enough thought, to figure out, what is a word?
2,595.75
3.3
And what is a number?
2,599.05
1.28
Only accepting, ultimately, numbers.
2,600.33
2.835
>> So it turns out that this isn't all that expressive.
2,605.69
4.54
so far.
2,610.23
0.68
So, yay, last time we went pretty quickly
2,610.91
2.78
into implementing games, and animation, and artistic works in Scratch.
2,613.69
4.63
And here, we are being content with hello world, and hello 50.
2,618.32
3.94