Secret
Key Takeaways
Debugs a secret program using debug50
Full Transcript
welcome everyone my name is carter and today i'll show you my secret program you can run the program by typing dot slash secret into your terminal and if you type in the right password you should be able to see come on in so let's try it out i'll do dot slash secret and maybe i don't know the secret phrase so i'll just say let me in and which point i don't get any response so let me try it again and do dot secret maybe password is the password here but it's not and i'll just reveal to you that the password is please so if i type dot secret and i type in please i should see come on in but i don't and so what's the problem here well maybe i should look into my code and maybe step through it bit by bit so i'll do code secret.c and i can see the very top of my code starting with this main void function to step through my code remember we can use debug 50 to set a breakpoint or place to pause in our code so i can go to this left side here find a pale red circle and turn it into a bright red circle as i click it and set that pause point or that break point now i can do debug 50 of secret and then my code should boot up and i should be able to pause right at that moment i'm asking the user for their secret phrase of course i have to actually step over that line for it to actually run my program so i'll then step over and i can type in my secret phrase of please okay so that seems pretty good i see that phrase becomes please and correct is currently false but it should change to true after i do this check phrase function so i'll step over check phrase and i see it's actually still false and so of course if i run past line 13 nothing will happen i actually won't print to come on in so at this point debug 50 seems to be not really helping me here right i've walked through my entire program but i haven't seen what went wrong in my code well debug 50 has this option to step into a function actually dive in and see what's happening underneath that hood of that function so what i can do is go to debug 50 again and run debug 50 with secret wait for my code to go to that breakpoint again and i'll walk through that first piece where i type in my phrase please but now instead of stepping over this check phrase function i actually want to dive into it and see what's going on underneath there so i'll do step into in debug 50 and then see i'm setting my password to be please so if i step over line 22 i should see that password becomes please as it does on this left hand side and now when i check for if phrase is password i should actually be able to return true because it seems that phrase is the same as password so i'll step over that and see well actually i get to line 29 and this is kind of subtle but in c you can't compare two strings using two equal signs you actually use a different function called string compare or str cmp for short so to use stir compare i can use str cmp and give it two arguments phrase and password and with these two inputs stir compare will tell me are they exactly equivalent or not if they are equivalent strcmp or store compare will give me 0 as a value back so now my code is saying if these strings are equivalent and i know they are because strike compare is giving me zero i can go ahead and return true and say this is the correct password so with this new code here i should be able to exit debug 50 and go back to the terminal and now i can make secret again run secret type in my password of please and now there it is it says come on in and with that we've seen how debug 50 can help us not only step over our code but dive into functions and see the bugs inside of them
Original Description
***
This is CS50, Harvard University's introduction to the intellectual enterprises of computer science and the art of programming.
***
HOW TO SUBSCRIBE
http://www.youtube.com/subscription_center?add_user=cs50tv
HOW TO TAKE CS50
edX: https://cs50.edx.org/
Harvard Extension School: https://cs50.harvard.edu/extension
Harvard Summer School: https://cs50.harvard.edu/summer
OpenCourseWare: https://cs50.harvard.edu/x
HOW TO JOIN CS50 COMMUNITIES
Discord: https://discord.gg/T8QZqRx
Ed: https://cs50.harvard.edu/x/ed
Facebook Group: https://www.facebook.com/groups/cs50/
Faceboook Page: https://www.facebook.com/cs50/
GitHub: https://github.com/cs50
Gitter: https://gitter.im/cs50/x
Instagram: https://instagram.com/cs50
LinkedIn Group: https://www.linkedin.com/groups/7437240/
LinkedIn Page: https://www.linkedin.com/school/cs50/
Reddit: https://www.reddit.com/r/cs50/
Quora: https://www.quora.com/topic/CS50
Slack: https://cs50.edx.org/slack
Snapchat: https://www.snapchat.com/add/cs50
Twitter: https://twitter.com/cs50
YouTube: http://www.youtube.com/cs50
HOW TO FOLLOW DAVID J. MALAN
Facebook: https://www.facebook.com/dmalan
GitHub: https://github.com/dmalan
Instagram: https://www.instagram.com/davidjmalan/
LinkedIn: https://www.linkedin.com/in/malan/
Quora: https://www.quora.com/profile/David-J-Malan
Twitter: https://twitter.com/davidjmalan
***
CS50 SHOP
https://cs50.harvardshop.com/
***
LICENSE
CC BY-NC-SA 4.0
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License
https://creativecommons.org/licenses/by-nc-sa/4.0/
David J. Malan
https://cs.harvard.edu/malan
malan@harvard.edu
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from CS50 · CS50 · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Hello, World: Hadi Partovi
CS50
Content Distribution and Archival in a Digital Age
CS50
CS50 2014 - Week 1
CS50
CS50 2014 - Week 3
CS50
CS50 2014 - Week 0, continued
CS50
CS50 2014 - Week 4
CS50
Week 3, continued
CS50
Quiz 0 Review
CS50
CS50 2014 - Week 3, continued
CS50
CS50 2014 - Week 7
CS50
CS50 2014 - Week 7, continued
CS50
Breaking Through The (Google) Glass Ceiling by Christopher Bartholomew
CS50
Introduction to Amazon Web Services by Leo Zhadanovsky
CS50
CS50 2014 - Week 9
CS50
How to Build Innovative Technologies by Abby Fichtner
CS50
Light Your World (with Hue Bulbs) by Dan Bradley
CS50
Building Dynamic Web Apps with Laravel by Eric Ouyang
CS50
CS50 2014 - CS50 Lecture by Steve Ballmer
CS50
CS50 2014 - Week 10
CS50
This is CS50 with Steve Ballmer?
CS50
Meteor: a better way to build apps by Roger Zurawicki
CS50
Data Analysis in R by Dustin Tran
CS50
Data Visualization and D3 by David Chouinard
CS50
CS50 2014 - Week 6
CS50
Build Tomorrow's Library by Jeffrey Licht
CS50
CS50 2014 - Week 9, continued
CS50
Essential Scale-Out Computing by James Cuff
CS50
iOS App Development with Swift by Dan Armendariz
CS50
Sam Clark Leads Yale Students on Tour to CS50 at Harvard
CS50
3D Modeling and Manufacture by Ansel Duff
CS50
CS50 2014 - Week 5, continued
CS50
hello, world
CS50
CS50 2014 - Deep Thoughts - Hash Table
CS50
CS50 2014 - Deep Thoughts - Binary Tree
CS50
CS50 2014 - Deep Thoughts - Scratch
CS50
CS50 2014 - Deep Thoughts - MySQL
CS50
LaunchCode Visits CS50
CS50
CS50 Live, Episode 100
CS50
CS50 Field Trip to Google
CS50
This is CS50 AP
CS50
Week 4: Monday - CS50 2011 - Harvard University
CS50
Week 2: Wednesday - CS50 2011 - Harvard University
CS50
Week 1: Wednesday - CS50 2011 - Harvard University
CS50
Week 11: Monday - CS50 2011 - Harvard University
CS50
Week 3: Wednesday - CS50 2011 - Harvard University
CS50
Week 12: Monday - CS50 2011 - Harvard University
CS50
Week 1: Friday - CS50 2011 - Harvard University
CS50
Week 3: Monday - CS50 2011 - Harvard University
CS50
Week 10: Wednesday - CS50 2011 - Harvard University
CS50
Week 2: Monday - CS50 2011 - Harvard University
CS50
Week 9: Monday - CS50 2011 - Harvard University
CS50
Week 7: Monday - CS50 2011 - Harvard University
CS50
Week 5: Monday - CS50 2011 - Harvard University
CS50
Week 5: Wednesday - CS50 2011 - Harvard University
CS50
Week 7: Wednesday - CS50 2011 - Harvard University
CS50
Week 8: Monday - CS50 2011 - Harvard University
CS50
Week 9: Wednesday - CS50 2011 - Harvard University
CS50
Week 8: Wednesday - CS50 2011 - Harvard University
CS50
Week 10: Monday - CS50 2011 - Harvard University
CS50
Week 2: Wednesday - CS50 2010 - Harvard University
CS50
More on: AI Pair Programming
View skill →Related Reads
📰
📰
📰
📰
I Bought 128GB of Unified Memory to Run Local Coding Models. Here’s What Actually Worked.
Medium · LLM
Companies Still Running Coding Interviews Will Be the Losers of the AI Era
Medium · Data Science
Pre-allocate Like a Pro
Dev.to · Sukhpinder Singh
The Real Divide in the AI Economy Isn't Human vs. Machine
Hackernoon
🎓
Tutor Explanation
DeepCamp AI