text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
write the name of the
variable that you want | 2,067.19 | 1.989 |
to plug in into that format
code, or format specifier, | 2,069.179 | 4.611 |
percent s for strings. | 2,073.79 | 1.679 |
And now if I've saved my file,
I go back down to my terminal. | 2,075.469 | 3.721 |
And I type Make String,
because, again, the name of this | 2,079.19 | 3.68 |
file that I chose before is string.c. | 2,082.87 | 2.64 |
>> So I'm going to say Make String, enter. | 2,085.51 | 3 |
Oh my goodness, look at all of
the mistakes we've made already. | 2,088.51 | 3.04 |
And this is-- what, this is really
like a six, seven line program? | 2,091.55 | 3.99 |
So this is where it can very
quickly get overwhelming. | 2,095.54 | 2.25 |
>> This terminal window has
now just regurgitated | 2,097.79 | 3.1 |
a huge number of error messages. | 2,100.89 | 2.34 |
Surely, I don't have more error
messages than I have lines of code. | 2,103.23 | 4.33 |
So what is going on? | 2,107.56 | 1.12 |
>> Well, the best strategy
to do anytime you | 2,108.68 | 2.24 |
do encounter an overwhelming
list of errors like that, | 2,110.92 | 2.79 |
is scroll back, look for the command
you just ran, which in my case | 2,113.71 | 2.98 |
is make string. | 2,116.69 | 1.33 |
Look at what make did, and that's that
long Clang command, no big deal there. | 2,118.02 | 3.61 |
>> But the red is bad. | 2,121.63 | 1.32 |
Green is trying to be
gentle and helpful. | 2,122.95 | 1.8 |
But it's still bad, in this case. | 2,124.75 | 1.39 |
But where is it bad? | 2,126.14 | 1.37 |
>> String.c, line five, character five. | 2,127.51 | 3.94 |
So this is just common convention. | 2,131.45 | 1.48 |
Something colon something means
line number and character number. | 2,132.93 | 3.13 |
Error, use of undeclared
identifier string. | 2,136.06 | 5.02 |
Did you mean standard in? | 2,141.08 | 1.82 |
>> So, unfortunately, Clang
is trying to be helpful. | 2,142.9 | 2.63 |
But it's wrong, in this case. | 2,145.53 | 1.32 |
No, Clang, I did not mean standard IO. | 2,146.85 | 2.5 |
I meant that on line one, yes. | 2,149.35 | 1.72 |
>> But line five is this one here. | 2,151.07 | 2.35 |
And Clang does not
understand S-T-R-I-N-G. | 2,153.42 | 3.62 |
It's an undeclared identifier, a
word it just has never seen before. | 2,157.04 | 4.45 |
And that's because C, the language
we're writing code in right now, | 2,161.49 | 4.24 |
does not have variables called strings. | 2,165.73 | 2.34 |
>> It doesn't, by default, support
something called a string. | 2,168.07 | 3.31 |
That's a CS50 piece of
jargon, but very conventional. | 2,171.38 | 5.37 |
But I can fix this as follows. | 2,176.75 | 1.85 |
>> If I add one line of code
to the top of this program, | 2,178.6 | 3.49 |
include CS50.h, which is another file
somewhere inside of CS50 IDE, somewhere | 2,182.09 | 5.8 |
on the hard drive, so to speak,
of the Ubuntu operating system | 2,187.89 | 2.93 |
that I'm running, that
is the file that's | 2,190.82 | 2.77 |
going to teach the operating
system what a string is, just | 2,193.59 | 5.15 |
like standard io.h is the file
in the operating system that's | 2,198.74 | 3.19 |
going to teach it what printf is. | 2,201.93 | 2.5 |
>> Indeed, we would have gotten
a very similar message | 2,204.43 | 2.38 |
if IO had admitted standard
IO.h and tried to use printf. | 2,206.81 | 3.79 |
So I'm going to go ahead and just
take Control L to clear my screen. | 2,210.6 | 3.032 |
Or you can type clear and it will
just clear the terminal window. | 2,213.632 | 2.708 |
But you can still scroll back in time. | 2,216.34 | 1.68 |
>> And I'm going to rerun Make String. | 2,218.02 | 3.08 |
Cross my fingers this time, Enter. | 2,221.1 | 2.56 |
Oh my God, it worked. | 2,223.66 | 1.72 |
it shows me a long cryptic command
that is what Make generated via Clang, | 2,225.38 | 3.9 |
but no error messages. | 2,229.28 | 1.18 |
So realize, even though
you might get completely | 2,230.46 | 2 |
overwhelmed with the
number of error messages, | 2,232.46 | 2.02 |
it just might be this annoying cascading
effect, where Clang doesn't understand | 2,234.48 | 3.06 |
one thing, which means it then
doesn't understand the next word, | 2,237.54 | 2.08 |
or the next line. | 2,239.62 | 0.94 |
And so it just chokes on your code. | 2,240.56 | 2.29 |
But the fix might be simple. | 2,242.85 | 1.59 |
And so always focus on the
very first line of output. | 2,244.44 | 3.382 |
And if you don't
understand it, just look | 2,247.822 | 1.708 |
for keywords that might be
clues, and the line number, | 2,249.53 | 2.95 |
and the character, where
that mistake might be. | 2,252.48 | 2.17 |
>> Now let me go ahead and type
dot slash, string, enter. | 2,254.65 | 5.678 |
Hm, it's not saying hello anything. | 2,260.328 | 4.012 |
Why? | 2,264.34 | 1.87 |
Well, recall, where is it running? | 2,266.21 | 1.96 |
>> It's probably stuck at the moment
in a loop, if you will, on line six, | 2,268.17 | 5.56 |
because Get String by design,
written by CS50 staff, | 2,273.73 | 3.22 |
is literally meant to just sit
there waiting, and waiting, | 2,276.95 | 3.4 |
and waiting for a string. | 2,280.35 | 1.5 |
All we mean by string is human input. | 2,281.85 | 1.942 |
So you know what? | 2,283.792 | 0.708 |
Let me go ahead. | 2,284.5 | 0.666 |
And just on a whim, let me
type my name, David, enter. | 2,285.166 | 3.538 |
Now I have a more dynamic program. | 2,288.704 | 1.416 |
It said, hello David. | 2,290.12 | 1.12 |
>> If I go ahead and run this again,
let me try say Zamila name, enter. | 2,291.24 | 5.04 |
And now we have a dynamic program. | 2,296.28 | 1.66 |
I haven't hard coded world. | 2,297.94 | 1.44 |
I haven't hard coded
name, or David, or Zamila. | 2,299.38 | 2.38 |
>> Now it's much more like the programs
we know, where if it take input, | 2,301.76 | 3.59 |
it produces slightly different output. | 2,305.35 | 2.52 |
Now, this is not the best
user experience, or UX. | 2,307.87 | 3.15 |
I run the program. | 2,311.02 | 1.98 |
>> I don't know what I'm supposed
to do, unless I actually look at | 2,313 | 2.83 |
or remember the source code. | 2,315.83 | 1.46 |
So let's make the user
experience a little better | 2,317.29 | 2.35 |
with the simplest of things. | 2,319.64 | 1.6 |
Let me go back into this
program, and simply say printf. | 2,321.24 | 3.542 |
>> And let me go ahead and say name, colon,
and a space, and then a semi-colon. | 2,324.782 | 4.088 |
And just for kicks, no backlash n. | 2,328.87 | 2.3 |
And that's deliberate,
because I don't want | 2,331.17 | 1.81 |
the prompt to move to the next line. | 2,332.98 | 1.61 |
>> I want to, instead, do this, make string
to recompile my code into new machine | 2,334.59 | 4.21 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.