Secret

CS50 · Beginner ·💻 AI-Assisted Coding ·4y ago

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 Hello, World: Hadi Partovi
Hello, World: Hadi Partovi
CS50
2 Content Distribution and Archival in a Digital Age
Content Distribution and Archival in a Digital Age
CS50
3 CS50 2014 - Week 1
CS50 2014 - Week 1
CS50
4 CS50 2014 - Week 3
CS50 2014 - Week 3
CS50
5 CS50 2014 - Week 0, continued
CS50 2014 - Week 0, continued
CS50
6 CS50 2014 - Week 4
CS50 2014 - Week 4
CS50
7 Week 3, continued
Week 3, continued
CS50
8 Quiz 0 Review
Quiz 0 Review
CS50
9 CS50 2014 - Week 3, continued
CS50 2014 - Week 3, continued
CS50
10 CS50 2014 - Week 7
CS50 2014 - Week 7
CS50
11 CS50 2014 - Week 7, continued
CS50 2014 - Week 7, continued
CS50
12 Breaking Through The (Google) Glass Ceiling by Christopher Bartholomew
Breaking Through The (Google) Glass Ceiling by Christopher Bartholomew
CS50
13 Introduction to Amazon Web Services by Leo Zhadanovsky
Introduction to Amazon Web Services by Leo Zhadanovsky
CS50
14 CS50 2014 - Week 9
CS50 2014 - Week 9
CS50
15 How to Build Innovative Technologies by Abby Fichtner
How to Build Innovative Technologies by Abby Fichtner
CS50
16 Light Your World (with Hue Bulbs) by Dan Bradley
Light Your World (with Hue Bulbs) by Dan Bradley
CS50
17 Building Dynamic Web Apps with Laravel by Eric Ouyang
Building Dynamic Web Apps with Laravel by Eric Ouyang
CS50
18 CS50 2014 - CS50 Lecture by Steve Ballmer
CS50 2014 - CS50 Lecture by Steve Ballmer
CS50
19 CS50 2014 - Week 10
CS50 2014 - Week 10
CS50
20 This is CS50 with Steve Ballmer?
This is CS50 with Steve Ballmer?
CS50
21 Meteor: a better way to build apps by Roger Zurawicki
Meteor: a better way to build apps by Roger Zurawicki
CS50
22 Data Analysis in R by Dustin Tran
Data Analysis in R by Dustin Tran
CS50
23 Data Visualization and D3 by David Chouinard
Data Visualization and D3 by David Chouinard
CS50
24 CS50 2014 - Week 6
CS50 2014 - Week 6
CS50
25 Build Tomorrow's Library by Jeffrey Licht
Build Tomorrow's Library by Jeffrey Licht
CS50
26 CS50 2014 - Week 9, continued
CS50 2014 - Week 9, continued
CS50
27 Essential Scale-Out Computing by James Cuff
Essential Scale-Out Computing by James Cuff
CS50
28 iOS App Development with Swift by Dan Armendariz
iOS App Development with Swift by Dan Armendariz
CS50
29 Sam Clark Leads Yale Students on Tour to CS50 at Harvard
Sam Clark Leads Yale Students on Tour to CS50 at Harvard
CS50
30 3D Modeling and Manufacture by Ansel Duff
3D Modeling and Manufacture by Ansel Duff
CS50
31 CS50 2014 - Week 5, continued
CS50 2014 - Week 5, continued
CS50
32 hello, world
hello, world
CS50
33 CS50 2014 - Deep Thoughts - Hash Table
CS50 2014 - Deep Thoughts - Hash Table
CS50
34 CS50 2014 - Deep Thoughts - Binary Tree
CS50 2014 - Deep Thoughts - Binary Tree
CS50
35 CS50 2014 - Deep Thoughts - Scratch
CS50 2014 - Deep Thoughts - Scratch
CS50
36 CS50 2014 - Deep Thoughts - MySQL
CS50 2014 - Deep Thoughts - MySQL
CS50
37 LaunchCode Visits CS50
LaunchCode Visits CS50
CS50
38 CS50 Live, Episode 100
CS50 Live, Episode 100
CS50
39 CS50 Field Trip to Google
CS50 Field Trip to Google
CS50
40 This is CS50 AP
This is CS50 AP
CS50
41 Week 4: Monday - CS50 2011 - Harvard University
Week 4: Monday - CS50 2011 - Harvard University
CS50
42 Week 2: Wednesday - CS50 2011 - Harvard University
Week 2: Wednesday - CS50 2011 - Harvard University
CS50
43 Week 1: Wednesday - CS50 2011 - Harvard University
Week 1: Wednesday - CS50 2011 - Harvard University
CS50
44 Week 11: Monday - CS50 2011 - Harvard University
Week 11: Monday - CS50 2011 - Harvard University
CS50
45 Week 3: Wednesday - CS50 2011 - Harvard University
Week 3: Wednesday - CS50 2011 - Harvard University
CS50
46 Week 12: Monday - CS50 2011 - Harvard University
Week 12: Monday - CS50 2011 - Harvard University
CS50
47 Week 1: Friday - CS50 2011 - Harvard University
Week 1: Friday - CS50 2011 - Harvard University
CS50
48 Week 3: Monday - CS50 2011 - Harvard University
Week 3: Monday - CS50 2011 - Harvard University
CS50
49 Week 10: Wednesday - CS50 2011 - Harvard University
Week 10: Wednesday - CS50 2011 - Harvard University
CS50
50 Week 2: Monday - CS50 2011 - Harvard University
Week 2: Monday - CS50 2011 - Harvard University
CS50
51 Week 9: Monday - CS50 2011 - Harvard University
Week 9: Monday - CS50 2011 - Harvard University
CS50
52 Week 7: Monday - CS50 2011 - Harvard University
Week 7: Monday - CS50 2011 - Harvard University
CS50
53 Week 5: Monday - CS50 2011 - Harvard University
Week 5: Monday - CS50 2011 - Harvard University
CS50
54 Week 5: Wednesday - CS50 2011 - Harvard University
Week 5: Wednesday - CS50 2011 - Harvard University
CS50
55 Week 7: Wednesday - CS50 2011 - Harvard University
Week 7: Wednesday - CS50 2011 - Harvard University
CS50
56 Week 8: Monday - CS50 2011 - Harvard University
Week 8: Monday - CS50 2011 - Harvard University
CS50
57 Week 9: Wednesday - CS50 2011 - Harvard University
Week 9: Wednesday - CS50 2011 - Harvard University
CS50
58 Week 8: Wednesday - CS50 2011 - Harvard University
Week 8: Wednesday - CS50 2011 - Harvard University
CS50
59 Week 10: Monday - CS50 2011 - Harvard University
Week 10: Monday - CS50 2011 - Harvard University
CS50
60 Week 2: Wednesday - CS50 2010 - Harvard University
Week 2: Wednesday - CS50 2010 - Harvard University
CS50

Related Reads

📰
I Bought 128GB of Unified Memory to Run Local Coding Models. Here’s What Actually Worked.
Learn how to set up a local coding model on a MacBook Pro M5 with 128GB of unified memory for AI-assisted coding
Medium · LLM
📰
Companies Still Running Coding Interviews Will Be the Losers of the AI Era
Companies that still rely on traditional coding interviews will be left behind in the AI era, as AI-generated code becomes increasingly prevalent
Medium · Data Science
📰
Pre-allocate Like a Pro
Learn how to pre-allocate memory like a pro in C# 15 for efficient coding
Dev.to · Sukhpinder Singh
📰
The Real Divide in the AI Economy Isn't Human vs. Machine
Developers who combine AI with strong engineering fundamentals will thrive in the AI economy, rather than being replaced by machines
Hackernoon
Up next
Claude Code Local Google Ads: Automate Everything ($730K Earned)
Jono Catliff
Watch →