1 00:00:09,316 --> 00:00:11,376 >> 좋아, 환영 다시 씨에스 - 50. 2 00:00:11,376 --> 00:00:15,646 이것은 1 주일의 시작입니다 그것은 이번 주에 우리가 잠수 그래서 3 00:00:15,646 --> 00:00:19,166 실제 프로그래밍에 함께 현대적인 프로그래밍 언어 4 00:00:19,166 --> 00:00:21,636 과 떨어져 애타게 시작 기본적인 빌딩 블록의 5 00:00:21,636 --> 00:00:24,026 저 솔직히 우리를 수행할 것입니다 전체 학기를 통해. 6 00:00:24,236 --> 00:00:26,596 순간 그 기타에 그게 뭘 의미하는대로 7 00:00:26,636 --> 00:00:28,916 하지만 빨리 하나, 당신이 할 오늘 인쇄물을 가지고 8 00:00:28,916 --> 00:00:29,966 모든 소스 코드의 9 00:00:29,966 --> 00:00:32,066 우리가 오늘 사용할 금 또한. 10 00:00:32,316 --> 00:00:34,146 당신이 찾아낼거야 그들이 라인 번호가 11 00:00:34,146 --> 00:00:35,036 그래서 만약 당신이 들어본 12 00:00:35,036 --> 00:00:37,236 언어의 기본이라고 그 사실은 언어의 13 00:00:37,236 --> 00:00:39,266 작년부터 어디서 실제로 인간의 방법으로 14 00:00:39,306 --> 00:00:42,486 입력 라인 10, 라인 20 라인 30, 15 00:00:42,486 --> 00:00:44,226 그리고 당신은 당신의 쓴 이 오른쪽에있는 코드입니다. 16 00:00:44,226 --> 00:00:48,116 그래서 인문 사람 이었어요 떠나는에 영리 접근 방 17 00:00:48,116 --> 00:00:50,786 당신이 원하는 경우 나중에에 코드를 좀 더 라인을 추가합니다. 18 00:00:50,786 --> 00:00:53,196 당신이 그것을 세워놓을 수도 있었 11과 19 라인, 사이 19 00:00:53,506 --> 00:00:56,256 정말 규모 않았어 특히. 20 00:00:56,256 --> 00:00:57,996 이것은 단지 출력입니다 줄 번호, 21 00:00:57,996 --> 00:00:59,516 그래서 당신이 쓰는되지 않습니다 그 숫자가 22 00:00:59,516 --> 00:01:00,596 하지만 난 그들에게 자주 참조됩니다. 23 00:01:01,096 --> 00:01:02,516 근무 시간은있다 진행되었습니다. 24 00:01:03,046 --> 00:01:04,806 당신이 오길 원한다면 중 쿼드로 놀러 25 00:01:04,806 --> 00:01:07,136 또는 퀸시 회관 식당 홀 오늘 저녁 26 00:01:07,136 --> 00:01:09,066 또는 다음 날 저녁이 들러 않습니다. 27 00:01:09,066 --> 00:01:10,666 교육 연구원 것입니다 해당 인증 기관과 함께 28 00:01:10,666 --> 00:01:12,616 채팅 그냥 전표에 과정에 대한 29 00:01:12,616 --> 00:01:14,946 당신의 상처와 함께 당신을 도울 프로젝트 아니면 그냥 일반적으로 걸어 30 00:01:14,946 --> 00:01:17,466 밖과 지출 저녁에 공동의 환경의 더. 31 00:01:17,766 --> 00:01:22,026 그리고 섹션, 우린 sectioning 프로세스를 가지고 32 00:01:22,026 --> 00:01:24,336 공식적으로 시작 오늘 밤 자정, 주위에 33 00:01:24,336 --> 00:01:26,216 그래서 CS50.net 's의 홈 페이지를 확인 34 00:01:26,216 --> 00:01:28,816 우리는 발표를해야합니다 거기로 어떻게 절을 참조하십시오. 35 00:01:29,096 --> 00:01:30,816 하지만 그래서 우리가 가진 공간이 숨쉬는 36 00:01:30,816 --> 00:01:32,876 그리고 우리는 시작되지 않습니다 학기에 나도 발을 급하게 37 00:01:32,876 --> 00:01:36,106 우리가 어떻게 할거야 없습니다 친밀한 섹션에서 시작 38 00:01:36,106 --> 00:01:38,816 어디로 12-15 학생 CF 한이 오는 주 39 00:01:38,816 --> 00:01:40,766 우리가 시작하는거야 그 2 주 후에 시간 40 00:01:40,976 --> 00:01:44,586 그리고이 첫 주, 이렇게 월요일 화요일 수요일 온다 41 00:01:44,586 --> 00:01:47,616 우리가 할거야 슈퍼 섹션 TFS 쌍의로 이끌었다. 42 00:01:47,616 --> 00:01:50,266 분명 더 큰거야 처음 일주일 동안 섹션 43 00:01:50,266 --> 00:01:51,946 당신이에 오신 걸 환영이야 어떤 그런 사람이 참석한다. 44 00:01:52,196 --> 00:01:56,316 위치는, 발표 예정 그래서 CS50.net/sections로 이동 45 00:01:56,386 --> 00:01:58,056 보고 현재 그것에 Google 캘린더. 46 00:01:58,056 --> 00:02:00,486 그리고 마지막으로 우리가 할 일은있다 센서 보드의 무리 47 00:02:00,696 --> 00:02:03,816 당신이 맡으하려는 경우 PSET - 0의 해커 에디션, 48 00:02:03,816 --> 00:02:07,076 하지만 보여준 것입니다 항상 우리가 기대하는 경우가 49 00:02:07,326 --> 00:02:09,496 우리는 거의 격려 과정을 모두 50 00:02:09,496 --> 00:02:12,726 , Standard Edition을 추구 그래서 아무 수단으로 생각해야 당신이 51 00:02:12,726 --> 00:02:14,946 당신은 떨어지고있다처럼 뒤에 또는 모서리를 절단 52 00:02:14,946 --> 00:02:17,056 그냥 수행하여 표준 의미 판 53 00:02:17,116 --> 00:02:17,736 대부분의 사람입니다. 54 00:02:18,266 --> 00:02:21,346 그래서 같이 말했다 우리는 숫자 지출 55 00:02:21,346 --> 00:02:23,956 당신이 이미 쓰셨습니다의 시간이 좀 긁어와 놀고 56 00:02:23,956 --> 00:02:25,566 그리고 우리가 실제로 , 눈 보관 57 00:02:25,646 --> 00:02:28,256 일부 단지의 어떤 종류의 호기심, 58 00:02:28,256 --> 00:02:30,716 제출을 갖고 이미오고. 59 00:02:31,096 --> 00:02:35,726 당신이 생각한다면 이제, 걱정하지 좀 대한 상조의 - 60 00:02:36,706 --> 00:02:39,806 약간의 버그가 가끔 마우스가 너무보고 응답 61 00:02:39,806 --> 00:02:44,316 화면이 시작되면 또 응답. 62 00:02:45,396 --> 00:02:45,766 우리가 간다. 63 00:02:46,086 --> 00:02:46,476 좋아. 64 00:02:46,616 --> 00:02:50,566 그래서 내가 나서서 이렇게 파는 그래서 만약 호기심이 세상에 대해서만, 65 00:02:50,566 --> 00:02:52,536 불과 약 10 % 클래스는 이미 제출했습니다. 66 00:02:52,536 --> 00:02:53,556 그래서 여기에 너무 걱정하지 마세요 67 00:02:53,556 --> 00:02:56,626 당신은 이미 주어진 뒤에있어 얼마나 신속하게 어떤 사람이 68 00:02:56,626 --> 00:02:57,556 제출하기 시작했다. 69 00:02:57,736 --> 00:02:58,996 약 30 명 제출. 70 00:02:58,996 --> 00:03:01,216 우리는이 약간있는 것으로 나타났습니다 재미있는 통계. 71 00:03:01,506 --> 00:03:04,036 그럼으로 기대 수도 당신들, 대부분의 72 00:03:04,036 --> 00:03:05,406 당신은 많은 Windows를 실행하고 있습니다. 73 00:03:05,696 --> 00:03:08,756 어떤 흥미로운 중 었죠 당신의 네온가 갔을 74 00:03:08,916 --> 00:03:12,016 그리고이 설치되어있어 새로운 반짝 이는 운영 체제 75 00:03:12,016 --> 00:03:14,236 애플, 스노우 레오파드, 우리가 볼 몇 가지 경우 76 00:03:14,236 --> 00:03:15,086 그 숫자를 변경합니다. 77 00:03:15,086 --> 00:03:17,376 아니면 누군가 뒤로 거기에, 우리가 볼 수 있도록 78 00:03:17,376 --> 00:03:18,296 때 그 숫자 들어오세요 79 00:03:18,496 --> 00:03:19,626 일부는 이러한 질문의 당신이 찾아낼거야 80 00:03:19,686 --> 00:03:22,276 PSET - 0에서 조사 진짜 단지 통계 목적. 81 00:03:22,276 --> 00:03:23,726 우린 할 일이 몇 가지 재미를 잘하도록 노력 할께 82 00:03:23,726 --> 00:03:25,086 데이터 전역과 학기. 83 00:03:25,546 --> 00:03:28,566 우리는 근본적으로 필요 없어 알아요 당신이에 태어난 도시, 84 00:03:28,566 --> 00:03:31,176 하지만 한복판의 우리가 나중에 시각화 수있다면 85 00:03:31,176 --> 00:03:32,376 뭔가 그 구글지도처럼. 86 00:03:32,646 --> 00:03:34,656 그러니 너무 당황해 하진 마쇼 그 해제합니다. 87 00:03:34,696 --> 00:03:37,436 당신이 걱정하는 경우는 모두 이 방에서, 전 - 전화 번호를 가지고 88 00:03:37,436 --> 00:03:38,426 별로 안의 경우. 89 00:03:38,476 --> 00:03:40,396 당신은 대부분하거나, 너희들의 대부분은 90 00:03:40,396 --> 00:03:43,436 이미 제출하신 , 일반 휴대폰을 가지고 91 00:03:43,436 --> 00:03:46,956 어느 완벽 때문에 사실 윌리 시간을 의미합니다 92 00:03:46,956 --> 00:03:49,986 차우 캘리포니아와 자신했다 셔틀 소년 목소리에 보냈다 93 00:03:50,036 --> 00:03:52,046 의 늦은 실제로 익숙해질 것입니다. 94 00:03:52,046 --> 00:03:53,746 그것은 복고 접근법의 일종 이죠 95 00:03:53,746 --> 00:03:56,566 응용 프로그램을 만들기 위해 프롬프트를 사용하여 touchtone 96 00:03:56,856 --> 00:03:59,866 하지만 정말로면 전화 617 - 버그 - CS50 97 00:03:59,996 --> 00:04:01,586 해당 서비스는 지금 살고있다. 98 00:04:01,586 --> 00:04:04,396 당신은 여기서 확인할 수 있습니다 빨리 쿼드이나 상관에게 99 00:04:04,396 --> 00:04:06,676 수업 후에 어디로 뿐만 아니라 24 / 7을 운영하고 있습니다. 100 00:04:06,886 --> 00:04:09,716 그리고 곧 오는 될거야 다른 기능을 왕창. 101 00:04:09,716 --> 00:04:11,636 그래서 지금은 그냥 셔틀 소년에 대한 옵션 1 102 00:04:11,886 --> 00:04:14,816 하지만 곧 올 것입니다 웨이크업 통화 옵션 103 00:04:14,816 --> 00:04:17,076 그건 우리가 용의자가됩니다 유용한 종류의 수 104 00:04:17,076 --> 00:04:19,486 중기 무렵, 시험 시간. 105 00:04:19,786 --> 00:04:21,996 우리는 약간 긴장하기 때문에 난이 역화 수있을 것 106 00:04:21,996 --> 00:04:24,906 완전히 우리는 발견한다면 버그 아침 가지고 107 00:04:24,906 --> 00:04:26,616 중간하지만 우리는거야 그것을 방지하려고합니다. 108 00:04:26,986 --> 00:04:29,246 오는 곧 너무합니다 홀 메뉴를 식사. 109 00:04:29,246 --> 00:04:31,346 당신이 알게하려는 경우 무엇을 오늘 점심에있다 110 00:04:31,346 --> 00:04:33,476 뭐 오늘 저녁, 감사합니다 전직 교육 친구에게, 111 00:04:33,476 --> 00:04:34,216 카토 Yuchiama [이 생각 맞춤법] 112 00:04:34,466 --> 00:04:36,326 우리는 옵션이 나타납니다 온라인뿐, 113 00:04:36,506 --> 00:04:37,496 그리고 곧 당신은거야 찾을 수 있습니다 114 00:04:37,496 --> 00:04:40,486 밖으로 할 때 다음 씨에스 - 50 근무 시간은 사실입니다. 115 00:04:40,696 --> 00:04:42,786 글쎄, 사람들이하는 경향이 같은 그들이 사는 곳을. 116 00:04:42,786 --> 00:04:45,376 이것은 작은 슬라이드입니다 그런 당신에게 감각을 준다 117 00:04:45,376 --> 00:04:47,146 의 PSETs 가지고 어디로 으로부터 제출되었습니다. 118 00:04:47,466 --> 00:04:50,076 신입생 종류의 있습니다 그것은 지금까지 보인다, 빈둥거리고 119 00:04:50,116 --> 00:04:51,736 비록 Holeworthy 그리고 매튜스가 보인다 120 00:04:51,736 --> 00:04:53,066 가지고 좀 괜찮은 우연이. 121 00:04:53,246 --> 00:04:55,176 그리고 여기에 사이 집이 무슨 강렬입니다 122 00:04:55,176 --> 00:04:57,926 그 유일한 집 분명히 다른 일을 123 00:04:57,926 --> 00:05:02,206 이번주는, Leverett했습니다 아이러니하게도 어느입니다 124 00:05:02,206 --> 00:05:05,366 가장 큰 주택과 마지막의 올해 데이터는 완벽히 125 00:05:05,366 --> 00:05:05,886 반대야. 126 00:05:05,886 --> 00:05:08,026 우리는에서 더 많은 학생들이 있었 어떤 것보다 Leverett 집 127 00:05:08,026 --> 00:05:10,256 그래서 아마도 우리가 이제 그 대가를 치르고. 128 00:05:10,256 --> 00:05:13,806 그러니 그냥 무작위 재미 씨에스 - 50에서 사실 여기에. 129 00:05:13,976 --> 00:05:16,586 그럼 이제 가자 잠수 들어갑니다 130 00:05:17,136 --> 00:05:19,276 이번 주 및 그러니까 이후 대부분입니다 131 00:05:19,276 --> 00:05:23,006 이 언어에 대한 전화 C와 당신이 노는 시작할 132 00:05:23,006 --> 00:05:25,186 C와의 네가하는 짓은 진짜로, 133 00:05:25,186 --> 00:05:27,046 전통적인 프로그래밍 언어. 134 00:05:27,046 --> 00:05:29,296 그래서 PSET 1, 어느 것입 이번주 금요일 실현할 수 135 00:05:29,296 --> 00:05:32,336 물론 웹사이트에 것입니다 뭐 태클있다 136 00:05:32,336 --> 00:05:33,986 그것은 친숙하지 않지만 여러분 중에 많은 분들에게, 137 00:05:33,986 --> 00:05:35,416 이 운영 체제는 전화 리눅스 [소리] 맞춤법, 가정 138 00:05:35,686 --> 00:05:38,036 또한이 언어 C가 전화를해서 우리가 많이 지출 139 00:05:38,036 --> 00:05:41,236 뭐야 C.에 학기 재미는 제가 특별히 생각 140 00:05:41,236 --> 00:05:43,296 이것에 대해 언어 그게 자바와는 달리 141 00:05:43,456 --> 00:05:46,226 그리고 스크립트 언어와는 달리 일부 당신, 알고있을 142 00:05:46,686 --> 00:05:50,186 PHP는, 파이썬, buzzwords처럼 이것은, 정말 낮은 수준이야. 143 00:05:50,186 --> 00:05:52,996 그냥 뭔가 부끄러워 라는 어셈블리 언어, 144 00:05:53,026 --> 00:05:54,946 우리가 어떤거야 눈에 나중에 학기에, 145 00:05:55,156 --> 00:05:57,986 그리고 그게 정말 진심 찾아 - 그레인 제어할 수 있습니다 146 00:05:57,986 --> 00:06:00,176 이상의 물건을 어디에 메모리에 추락한다 147 00:06:00,256 --> 00:06:02,966 같은 RAM에 당신은 어디에 실제로 문자열을 사용하여 148 00:06:02,966 --> 00:06:05,596 및 숫자 및 데이터베이스 그런 물건. 149 00:06:05,996 --> 00:06:09,296 그리고 그것은 동일한에서 작업을 수행할 수 시간은 정말 나쁜 일들을 할 수 있습니다. 150 00:06:09,296 --> 00:06:11,986 그래서 이들 중 많은 당신이 읽을 공격 151 00:06:11,986 --> 00:06:15,306 당신이 종류를 읽으면 출판물이나 웹사이트 152 00:06:15,626 --> 00:06:19,066 그 웹 사이트를 포함하고 서버를 통해 해킹들이 취해지고 153 00:06:19,066 --> 00:06:22,326 그래서 해커에 의해 이상 나아가,이 하루에 많이 154 00:06:22,326 --> 00:06:24,546 그 타협의 중 결과입니다 155 00:06:24,546 --> 00:06:26,136 그냥 바보 같은 실수 인간이 156 00:06:26,596 --> 00:06:29,466 또는 때때로 이상 미묘한 실수가 나오게 되죠 157 00:06:29,646 --> 00:06:32,706 때문에 웹사이트 또는 프로그램, 뭐든간에, 158 00:06:32,706 --> 00:06:37,676 C 또는 C + + 또는로 작성되었습니다 일부 관련 언어뿐만 아니라 159 00:06:37,866 --> 00:06:41,136 이 때문에 권력과 마찬가지로 온다 그들은 큰 책임이 말. 160 00:06:41,136 --> 00:06:43,686 당신은 많이 할 수 자신만의 데이터베이스에 손상, 161 00:06:44,016 --> 00:06:48,586 고객님의 보안 코딩으로하는 부적절하고 늘되지 않는 162 00:06:48,586 --> 00:06:49,836 특정 보안 문제. 163 00:06:50,016 --> 00:06:52,016 그리고 재미있는이야 난 결과로 생각 164 00:06:52,016 --> 00:06:53,366 에 대한 얘기 이 언어 165 00:06:53,366 --> 00:06:56,426 앞으로 몇 주입니다 정말 좀 이해가 166 00:06:56,426 --> 00:06:59,576 같은 사회 문제 같은 왜이 웹사이트가 해킹 거죠? 167 00:06:59,576 --> 00:07:01,216 어떻게 할 수있는 사람을 어쩌면 그렇게 할 168 00:07:01,216 --> 00:07:04,436 그리고 무엇보다 수 있습니다 일부에 지능형 솔루션 169 00:07:04,436 --> 00:07:06,486 문제의 우리 자신을 볼 것입니다. 170 00:07:06,736 --> 00:07:09,346 그래서 기스가 충족 C. 그래서 바라건대, 171 00:07:09,346 --> 00:07:11,906 설사 당신이 아래에 토하지 않았습니다 아직 어느 괜찮네, PSET 0합니까 172 00:07:11,996 --> 00:07:14,516 아직 시간이 많은 중, 당신 바라건대 지난주 감각을 가지고 173 00:07:14,516 --> 00:07:16,666 의 어떤 일부의 기본적인 빌딩 블록이 있습니다 174 00:07:16,666 --> 00:07:17,646 프로그래밍. 175 00:07:17,646 --> 00:07:19,346 한 진술과 같아요, 이, 할 176 00:07:19,346 --> 00:07:22,136 써있는데 뭔가 여부, 뭔가 움직여 어딘가 생각합니다. 177 00:07:22,466 --> 00:07:23,406 거기에 조건이있어. 178 00:07:23,486 --> 00:07:25,706 다음과 같은 경우이나요 사실입니다. 179 00:07:25,976 --> 00:07:28,416 당신이 필요한 경우에는 변수가 , 데이터의 조각을 주변에 유지 180 00:07:28,516 --> 00:07:31,066 그리고 우리는 약간 좀 봤어요 보다 정교한 주제 181 00:07:31,066 --> 00:07:34,366 스레드, 배수처럼 스크립트와 이벤트,이 능력 182 00:07:34,366 --> 00:07:35,856 하나의 스크립트에서 메시지를 보낼 수 183 00:07:35,856 --> 00:07:39,166 다른 동안 모든 같은 빌딩 블록은 C에 존재 184 00:07:39,166 --> 00:07:40,566 그들은 대부분의 언어에서 그러는 것처럼. 185 00:07:40,836 --> 00:07:43,136 게다가 당신은 무슨 생각 쓰기 시작하는 거예요 186 00:07:43,136 --> 00:07:46,486 PSET 1 이후로 가고있다 아래의 자세한 모습 187 00:07:46,486 --> 00:07:49,356 덜 가기를 좋아 정말 같은 생각이야. 188 00:07:49,356 --> 00:07:51,786 그리고 만약 당신이 하나의 중요한을 오늘 떨어져 포인트, 189 00:07:52,366 --> 00:07:55,536 당신은 알게 될 때 당신이 먼저 아래 프로그램을, 앉아 190 00:07:55,586 --> 00:07:58,406 아마도 처음 시간과 대부분의 C와의 가능성 191 00:07:58,406 --> 00:08:01,056 처음으로, 당신 것입니다 바보 같은 실수를 192 00:08:01,296 --> 00:08:03,706 당신은 이상의 스트레스거야 어떤 의미 세부 사항 193 00:08:03,796 --> 00:08:07,206 내 코드가 아닙니다 이유처럼 작업, 왜, 컴파일되지 않습니다 194 00:08:07,506 --> 00:08:09,616 그리고거야 확률 종기 일이 좀 어리석은 195 00:08:09,616 --> 00:08:11,856 그 세미콜론를 볼 수 4 라인 거기에 196 00:08:12,196 --> 00:08:14,106 당신이 실수로 같은거야 생략했습니다 그 197 00:08:14,236 --> 00:08:16,286 또는 당신이 떨어져 남는 어딘가에 따옴표 198 00:08:16,286 --> 00:08:17,126 또는 큰 따옴표. 199 00:08:17,276 --> 00:08:18,186 그리고 솔직히 이것은 하나입니다 200 00:08:18,186 --> 00:08:21,246 이유는 우리가 밖에서 먼저 시작 물론 지난주에 201 00:08:21,526 --> 00:08:22,266 스크래치 겠죠? 202 00:08:22,266 --> 00:08:24,896 당신은 걱정할 필요 없어 이 재미 사소한 점 203 00:08:25,186 --> 00:08:28,596 하지만 지금 우리가 가고있는 걸 실제 컴퓨터를 프로그래밍해야 204 00:08:28,846 --> 00:08:31,826 그리고 우리도 더해야 정확하고 그것이 수준의 205 00:08:31,826 --> 00:08:33,706 정밀,이 중 nitpickiness 수준 206 00:08:33,996 --> 00:08:35,156 그 사실은 중요치 않아. 207 00:08:35,196 --> 00:08:35,856 당신이 찾을 수 있기 때문에 208 00:08:35,856 --> 00:08:38,326 그 컴퓨터가 할 말 그대로 당신이 그것을 말한다 209 00:08:38,326 --> 00:08:40,836 어떻게, 그리고 당신이하지 않으면 라고 세미콜론 거기 210 00:08:40,836 --> 00:08:43,506 이 특정 언어로, 당신이 컴퓨터를 참견하지는 않는 단다 211 00:08:43,506 --> 00:08:45,246 이것이 마지막입니다 성명, 212 00:08:45,296 --> 00:08:46,716 당신이 만들고있어 모호한 것들. 213 00:08:47,106 --> 00:08:50,336 그래서 모호함이 나쁜 경향이 프로그램에 우리가 볼 수 있습니다. 214 00:08:50,616 --> 00:08:53,016 그럼 어떻게 이런 일이 가는거야 오늘처럼 찾기 시작? 215 00:08:53,016 --> 00:08:55,676 음, 빨리 맛보기 메시지, 성명은 지난 주에 봤는데 216 00:08:55,676 --> 00:08:58,546 안녕하세요, 세상이, 오,, 같은 작은 보라색 블록 217 00:08:58,546 --> 00:09:01,296 그리고 C는 이후거야 조금 더 애매한 태도를 보이는 218 00:09:01,296 --> 00:09:04,616 하루의 긴장했지만시 똑같은 생각 인쇄여, 219 00:09:04,616 --> 00:09:08,936 어떤 형식의 인쇄를 의미 세계의 메커니즘, Ohi 종류 220 00:09:08,936 --> 00:09:11,056 그리고 N을, 나 역슬래쉬 우리가 지난 주에 말했다 생각 221 00:09:11,056 --> 00:09:11,636 그게 무슨 뜻 이죠? 222 00:09:12,756 --> 00:09:15,216 새로운 라인. 그래서 당신은 할 앞으로도 절대로 그렇게 명시되어야 223 00:09:15,216 --> 00:09:17,556 어디에 당신이 원하는 키를 암살로 입력 224 00:09:17,556 --> 00:09:21,086 및 / N은 행위를 나타냅니다 키보드에서 Enter를 누를 때. 225 00:09:21,306 --> 00:09:23,006 그럼 그 어떤 진술의 수사를 시작하려고 226 00:09:23,006 --> 00:09:24,866 곧처럼 부용 표현, 227 00:09:24,866 --> 00:09:28,056 그래서이 일이 였죠 수 로 평가된다 true 또는 false로 1 228 00:09:28,056 --> 00:09:30,806 또는 0 또는 해제, 그러나 당신이 세상을보고 싶어요. 229 00:09:31,036 --> 00:09:33,466 그럼 지금은 뭘하는 데 사용 주황색과 녹색처럼 230 00:09:33,466 --> 00:09:35,196 저기 대신거야 가기 231 00:09:35,196 --> 00:09:36,896 조금 더 둘러 고등학교 수학, 232 00:09:37,196 --> 00:09:40,206 하지만 괄호 엑스 이하 Y를보다가 괄호를 마감했다. 233 00:09:40,206 --> 00:09:42,686 그리고 당신이 참여하고 싶다면 우린 이런 일이 함께 234 00:09:42,686 --> 00:09:45,026 같은 것들을 보러 간다고 앰퍼샌드 앰퍼샌드, 235 00:09:45,316 --> 00:09:47,386 그냥 돼었죠 C로 명명법 236 00:09:47,426 --> 00:09:49,666 부용의 아이디어와 있습니다. 237 00:09:50,366 --> 00:09:53,266 그리고의 개념이나, 경우 이 아니면 이런 말하고 싶지 238 00:09:53,626 --> 00:09:54,946 그것은 없을거야 이 아니면거야 239 00:09:54,946 --> 00:09:56,946 로 수직 수직 막대 바. 240 00:09:56,946 --> 00:09:58,356 그리고 그것은 어리석은 일이에요 이렇게 너무, 241 00:09:58,356 --> 00:10:01,156 우리가 어디있는거야 불가피 질문이 학기를 242 00:10:01,156 --> 00:10:03,236 어디 같이 수직 내 키보드의 술집? 243 00:10:03,236 --> 00:10:05,356 이것은 문자 없습니다 당신의 대부분은 일반적으로 사용 244 00:10:05,666 --> 00:10:08,566 그것은 보통과 교대의 Enter 키를 위 245 00:10:08,566 --> 00:10:10,416 일반적인 키보드에서 그것은 다를 것입니다. 246 00:10:10,416 --> 00:10:12,756 그러니 다시 매달아 안 최대 학기에 이른 247 00:10:12,756 --> 00:10:16,486 이런 바보 같은 세부 사항에 그들이 바보이기 때문에 248 00:10:16,486 --> 00:10:17,906 그리고 그들은 지적이야 시시한 249 00:10:18,136 --> 00:10:20,876 그래서 그냥 받아 사실은 이것이 무엇 250 00:10:20,876 --> 00:10:23,746 적어도 초기에는 일부에서 언어가 같다. 251 00:10:23,746 --> 00:10:25,576 그럼,에 대한 자세한 내용 흥미가 구조 252 00:10:25,646 --> 00:10:26,176 조건. 253 00:10:26,226 --> 00:10:29,786 엑스는 여러분을보다 지난 주에있다면 우리가 뭔가를 말하고 싶었어요. 254 00:10:30,086 --> 00:10:31,986 고도는 우리가 그러길 바래 다른 말. 255 00:10:32,226 --> 00:10:35,366 그럼, 이런 모양 중첩된 퍼즐의 한 조각 건설 256 00:10:35,366 --> 00:10:37,486 에서 이번 주에 왼쪽 이후 보는거야 257 00:10:37,486 --> 00:10:38,516 오른쪽에있는 물건처럼. 258 00:10:38,516 --> 00:10:40,216 그리고 다시는지고있어 조금 지저분 259 00:10:40,216 --> 00:10:42,436 하지만 여전히 기본이야 빌딩 블록 260 00:10:42,476 --> 00:10:46,416 만약 공간이 열린 괄호, 엑스 Y 닫기 괄호보다 적게 261 00:10:46,416 --> 00:10:49,086 중괄호, 본질적으로 대표 무슨 스크래치가 않습니다 262 00:10:49,086 --> 00:10:51,786 그래픽으로 받아들이면서 퍼즐 조각 비슷하게 263 00:10:51,786 --> 00:10:55,236 청크 또는 라인의 포옹 이런 중괄호와 코드입니다. 264 00:10:55,546 --> 00:10:57,376 인쇄 다시는 형식으로 인쇄할 수 있습니다. 265 00:10:57,416 --> 00:11:00,246 우리는 익숙한 따옴표 있어요 지금, 백슬래시 및 세미콜론. 266 00:11:00,286 --> 00:11:02,026 그래서 이미 오래 모자입니다. 267 00:11:02,026 --> 00:11:04,866 다른면 지금 우리가 가지고 두 번째 분기는 여기에, 다른 268 00:11:05,036 --> 00:11:07,806 제 3 지점 및 통지 다시 대칭에 걸쳐 269 00:11:07,806 --> 00:11:08,276 이 코드. 270 00:11:08,276 --> 00:11:11,396 우리가 곱슬 아용 열면 우리가 사물을 가까이 보인다 271 00:11:11,396 --> 00:11:12,976 대칭 할 수 있습니다. 272 00:11:13,036 --> 00:11:14,486 그렇게 될 것이다 중요뿐만 아니라. 273 00:11:14,876 --> 00:11:16,936 루프 그럼, 우리가 본 것들이 영원히 274 00:11:16,936 --> 00:11:18,346 과 시간의 몇 가지 숫자를 반복합니다. 275 00:11:18,596 --> 00:11:20,616 음,이 두 얼굴 작은 첫 눈에 이상해 276 00:11:20,666 --> 00:11:24,216 하지만 오른쪽 상단 거기에 우리가 가 1이 동안은 친절 277 00:11:24,216 --> 00:11:27,286 바보 루프에의 감각 1 왜냐하면 동안, 278 00:11:27,286 --> 00:11:28,076 그럼 무슨 뜻 이죠? 279 00:11:28,076 --> 00:11:30,746 음, 1 동의어이다 지금까지 우리가 본대로 280 00:11:30,746 --> 00:11:32,036 사실의 개념입니다. 281 00:11:32,266 --> 00:11:36,186 그래서 한동안 사실이게 않습니다 일이 일어날 것 같다 제안 282 00:11:36,236 --> 00:11:38,776 오른쪽 상단에 그 루프와 함께? 283 00:11:38,886 --> 00:11:41,506 그것은 영원히 가야거야 바로 진정한 사실이기 때문에 284 00:11:41,506 --> 00:11:42,916 그것은 변화 없을거야. 285 00:11:43,006 --> 00:11:44,526 하나는 변수가 아니라 안의 X, 286 00:11:44,736 --> 00:11:46,526 그게 아니라부터 Y 그건 아니에요 foo는 그것은 멀지 않아. 287 00:11:46,526 --> 00:11:49,796 그것은 어떤 자리 표시 자, 안 그래 말 그대로 진리의 값입니다 288 00:11:50,116 --> 00:11:52,956 정말 이건 의도적으로 무한 루프. 289 00:11:53,236 --> 00:11:55,306 지금은 아마 안을 최대한 활용 290 00:11:55,306 --> 00:11:57,506 무한 루프 여기서 당신은 말 그대로 원하지 않는다면 291 00:11:57,506 --> 00:11:59,836 프로그램을 작성하는 방법 때 두 번 클릭하거나 실행 292 00:11:59,836 --> 00:12:04,716 그리고 프롬프트 그냥 말합니다 ohi 광고 nauseum 영원히 293 00:12:04,716 --> 00:12:06,956 코드를 그대로 따름입니다 컴퓨터에서 가져온. 294 00:12:06,956 --> 00:12:10,416 그래서 때로는 우리가 보자 부정사 루프 좋다 295 00:12:10,416 --> 00:12:12,786 하지만 무한 루프 경우 어떻게든 밖으로들을 수 있습니다 296 00:12:12,786 --> 00:12:15,296 과 방법 밖에 나가 이렇게 할 수있는 동등한 297 00:12:15,296 --> 00:12:17,146 리눅스에서 볼 수 있습니다 금연의 힘 298 00:12:17,146 --> 00:12:18,236 특정 프로그램입니다. 299 00:12:18,236 --> 00:12:20,686 그리고,이 분명히 아니 진짜 프로그램이 있습니다 300 00:12:20,966 --> 00:12:22,566 왼쪽 마찬가지로 블록은 필요 없어 301 00:12:22,566 --> 00:12:24,796 그 때 녹색 깃발 클릭 블록 302 00:12:24,796 --> 00:12:26,706 어떤 스크립트를 시작 지난 주, 303 00:12:27,036 --> 00:12:28,496 이들은 완전한 프로그램 없습니다 304 00:12:28,496 --> 00:12:29,786 이건 그냥 미리보기입니다 지금까지. 305 00:12:29,786 --> 00:12:31,046 두고 보자고 우리 그들을 포장해야합니다 306 00:12:31,046 --> 00:12:32,356 그들을 실제 프로그램을 만들합니다. 307 00:12:32,596 --> 00:12:34,416 이제 오른쪽 하단에 있어요 아직 좀 더 이상한 308 00:12:34,416 --> 00:12:36,906 하지만 당신은 패턴이 없어요 매우 친숙한을 당할 것이다 309 00:12:36,906 --> 00:12:38,266 과 그것 때문 몹시 유용합니다. 310 00:12:38,446 --> 00:12:40,666 4 int 내가 0 도착. 311 00:12:40,666 --> 00:12:43,896 그래서이 변수를 선언 말합니다 나, 0으로 초기화했다. 312 00:12:44,186 --> 00:12:48,536 마 너무 오래 다음 난 10 미만이되고, 313 00:12:48,536 --> 00:12:49,716 그래서 중간 부분에는 314 00:12:49,716 --> 00:12:52,676 두 세미콜론 사이에 그것이 조건이야,라고 315 00:12:52,996 --> 00:12:56,006 그것은 유사한 정신가 너무 무슨 괄호에 이상이야 316 00:12:56,006 --> 00:12:57,786 그래도 재미 그 삽입구가 있었 습니다만 317 00:12:58,056 --> 00:13:01,396 그래서 미만 동안 10 일 다음 할 318 00:13:01,446 --> 00:13:03,846 그리고 당신의 마지막 소환 무슨 플러스 플러스 경향이 주 319 00:13:03,846 --> 00:13:04,306 넣어야 할 때는? 320 00:13:05,406 --> 00:13:08,746 증가, 그래서 효과 영어이 바닥 루프 중 하나입니다 321 00:13:08,746 --> 00:13:10,116 쉽게 설명하자면 뭘 할까? 322 00:13:10,566 --> 00:13:13,606 인쇄 ohi 10 번 읽혔습니다. 323 00:13:14,556 --> 00:13:16,016 맞아. 아니에요 재미있는 프로그램, 324 00:13:16,016 --> 00:13:19,236 하지만 또 뭐가 다른가 암호화된보고 문법은 것 같애 325 00:13:19,236 --> 00:13:20,496 아주 간단한 일이 다. 326 00:13:20,496 --> 00:13:22,706 그리고 그게 그렇게 될 것이다 지금은 새로운 빌딩 블록. 327 00:13:22,706 --> 00:13:23,856 변수 그럼 어때? 328 00:13:23,856 --> 00:13:25,926 글쎄,이 인간이 스크래치 코드 329 00:13:25,926 --> 00:13:28,316 상단 선언 변수는 반대했다. 330 00:13:28,316 --> 00:13:29,766 그것은 그것을 0으로 초기화 331 00:13:30,006 --> 00:13:33,136 그리고 분명히이 스크래치 코드는 영원히 말했다 값 332 00:13:33,136 --> 00:13:35,606 와이 작은 카운터 화면에 만화의 거품 333 00:13:35,606 --> 00:13:37,396 다음 변경됨 하나의 카운터 334 00:13:37,396 --> 00:13:39,576 그리고 우리는 말했 지난 주 플러스 플러스의 동등한. 335 00:13:39,886 --> 00:13:43,396 그 루프 그래서 거기, 그 스크래치는 구조가 효과를 나타냅니다 336 00:13:43,776 --> 00:13:45,646 0에서 최대 기대합니다. 337 00:13:45,716 --> 00:13:47,706 글쎄, 우리가 어떻게 구현합니까 C에서 같은 생각? 338 00:13:47,706 --> 00:13:49,216 글쎄, 그건 좀거야 이런 작은 선물. 339 00:13:49,306 --> 00:13:54,136 C에서 변수를 선언하기 위해 우리는 하여야 될보고 상대적으로 340 00:13:54,176 --> 00:13:56,296 간단하게 말하는 어떤 종류의 변수의 당신이 원하는거야? 341 00:13:56,536 --> 00:13:58,516 전 아카 int 정수 싶어요. 342 00:13:58,816 --> 00:14:00,756 뭘 할까 로 그 이름을 줄래? 343 00:14:00,756 --> 00:14:04,266 카운터. 뭘 할까 한번의 기본값을 지정? 344 00:14:04,926 --> 00:14:07,226 그래서 = 0 세미콜론 0옵니다. 345 00:14:07,306 --> 00:14:09,926 선언 변수라는 카운터, 그건 내가 지운대 346 00:14:09,926 --> 00:14:11,786 내부에서는 int을 집어 이 일은 Int 인? 347 00:14:11,786 --> 00:14:13,976 난 0 넣을 거예요 안으로 그것의 처음. 348 00:14:14,216 --> 00:14:17,196 이제이 루프 우리가 전에 본 1 수단이 광고를 할 동안 349 00:14:17,196 --> 00:14:20,076 인해서, 인쇄 F.하세요 이건 조금 흥미 350 00:14:20,076 --> 00:14:23,876 그리고 우리는 더 이상 알아보겠습니다 오늘 금요일에, 퍼센트 디 351 00:14:24,536 --> 00:14:26,946 이건 무슨 F는 인쇄 F.입니다 352 00:14:27,166 --> 00:14:30,146 우리가 인쇄 F는 뜻 말 , 서식이 지정된 문자열을 인쇄 353 00:14:30,476 --> 00:14:32,036 그럼 무슨 뜻이지 형식 문자열? 354 00:14:32,286 --> 00:14:35,016 그것은 컴퓨터에게 의미 다소이 값을 표시 355 00:14:35,016 --> 00:14:37,466 에 따라 다르게 그것은 어떤 타입의 값이. 356 00:14:37,726 --> 00:14:39,436 이제이 친절입니다 시시한 사건 357 00:14:39,436 --> 00:14:40,516 왜냐하면 우리가 뭘 인쇄 싶어? 358 00:14:40,856 --> 00:14:43,076 그냥 그 가치의 카운터, 내가 원하기 때문에 359 00:14:43,076 --> 00:14:45,486 본질적으로 구현하는 방법 스크래치 것좀 위, 360 00:14:45,776 --> 00:14:49,516 그래서 %로 디 금후, 정수에 대한 10 진수 의미합니다. 361 00:14:49,666 --> 00:14:50,896 정수 여기 놔. 362 00:14:51,136 --> 00:14:51,866 어떤 정수? 363 00:14:52,106 --> 00:14:55,756 음, 뭐든 넣어 정수 내부 변수 중 하나입니다 364 00:14:55,756 --> 00:14:57,246 그것은 쉼표 뒤에 온다. 365 00:14:57,596 --> 00:14:59,056 그래서 다시 기본 빌딩 블록. 366 00:14:59,396 --> 00:15:01,466 당신은 확실히 데리고 천만에요 이런 것들에 대한 작은 메모 367 00:15:01,466 --> 00:15:02,926 하지만 너무 자주 재발합니다 368 00:15:03,146 --> 00:15:05,086 이것이 바로 그 것입니다 빨리 낡은 모자된다. 369 00:15:05,086 --> 00:15:08,146 그리고 마지막 카운터 플러스 플러스, 그것은 단순히 증가를 의미 370 00:15:08,146 --> 00:15:09,466 카운터 다시 해. 371 00:15:09,706 --> 00:15:11,056 그래서 우리는 상처 하나, 우리는, C가있다 372 00:15:11,286 --> 00:15:12,786 기능들이있어 똑같은. 373 00:15:12,786 --> 00:15:15,056 난 당신이 가르쳤던 주 영과 PSET 0, 374 00:15:15,236 --> 00:15:17,056 단지 더 많은 즐거움 일어 뭔가를 얻을 375 00:15:17,056 --> 00:15:20,396 그리고 접근 방법을 사용하여 실행 위로 가기,하지만 당신은 실행거야 376 00:15:20,516 --> 00:15:23,806 일부의 일종으로 긁힌 자국과 천장의 377 00:15:23,806 --> 00:15:25,436 당신은 정말로 할 수없는 일이 378 00:15:25,436 --> 00:15:27,486 그것은 표현이 아니니까 충분히 언어. 379 00:15:27,686 --> 00:15:29,986 우리는 많은 것을 할 수있을거야 C와의 더 강력한 것을, 380 00:15:30,336 --> 00:15:32,936 훨씬 더 강력한 것들 PHP로와 자바 스크립트, 381 00:15:33,236 --> 00:15:35,906 당신은 같이한다 그래서 우리는,에 , 상승 궤도를 참조하십시오. 382 00:15:36,046 --> 00:15:37,846 그리고 마지막으로 우리가이 있어요 문제는 인벤토리를했다. 383 00:15:37,846 --> 00:15:41,266 어떤 프로그램을 지난 주에 그것을했다 내가 인벤토리를 사용하는가? 384 00:15:41,266 --> 00:15:44,846 네, 아마도 그 롤플레잉, 롤 플레잉 게임 385 00:15:44,846 --> 00:15:46,636 나는 어디로 이사를 좀 사람 위, 아래, 왼쪽 386 00:15:46,636 --> 00:15:48,656 오른쪽 수집 과일 그리고 그것을 발표 387 00:15:48,656 --> 00:15:49,606 카운터에있는 남자. 388 00:15:49,606 --> 00:15:54,026 글쎄, 난 과일을 지키기위한 벡터 배열, 일명,로 389 00:15:54,026 --> 00:15:56,876 일명 목록, 요쿠르트 우리가 이번 학기에들을 보자 390 00:15:56,876 --> 00:15:59,296 실제로 서로 다른가 유용한 의미. 391 00:15:59,456 --> 00:16:02,016 처음에는 우리가있다 라는 변수 목록. 392 00:16:02,016 --> 00:16:05,676 우리는 같은 문자열을 추가할 수 있습니다 오렌지, 그리고 내가 말할 문자열 393 00:16:05,676 --> 00:16:08,676 덧붙여 말하자면,이 컴퓨터가 과학은 순서에 대해 말하다 394 00:16:08,676 --> 00:16:11,866 대표 자 단어, 문장, 뭐든간에. 395 00:16:12,576 --> 00:16:14,426 그래서거야 C로 표현할 396 00:16:14,426 --> 00:16:18,566 아마도 대부분의 암호를 사용하여 아직 번째 문자 스타 재고는, 397 00:16:18,686 --> 00:16:21,386 열린 브라켓 크기 폐쇄 브라켓 세미콜론. 398 00:16:21,386 --> 00:16:23,836 그리고 우리는 많은 지출을하지 않습니다 배열에 시간이 주 399 00:16:24,106 --> 00:16:27,156 당신이이기 때문에 C로 거의 다 이렇게 얘기하고 하드웨어에 400 00:16:27,226 --> 00:16:29,586 그렇게 때문에 RAM이 넘는 많은 제어 401 00:16:29,586 --> 00:16:31,166 어디에 컴퓨터를 , 물건을두고 402 00:16:31,576 --> 00:16:34,136 좀 더 명시해야 C로 처음보다. 403 00:16:34,136 --> 00:16:37,136 당신은 내가 원하는 말을 해줘 야지 의 배열 사이즈가 어떻게? 404 00:16:37,356 --> 00:16:39,286 글쎄, 당신은 말하지 그나 저나 컴퓨터 405 00:16:39,286 --> 00:16:42,676 이 브라켓 표기법의 방법 큰 당신이 수, 배열을 원한다 406 00:16:42,886 --> 00:16:46,276 크기는 실제로 변수이다 그래서 어떤 상수 값을 407 00:16:46,496 --> 00:16:48,906 그 정의해야합니다 다른 곳에서 내 프로그램입니다. 408 00:16:48,906 --> 00:16:50,046 그것은 단순히 화면 아니에요. 409 00:16:50,326 --> 00:16:53,976 그런데 때 넣었 으면 좋겠어 특정 위치에 뭔가 410 00:16:53,976 --> 00:16:56,666 배열에서조차 [소리 ] 위치처럼, 우리는 말할 게요 411 00:16:56,666 --> 00:16:58,116 내가 손가락을 사용하여 그만두고 따옴표 오늘 412 00:16:58,116 --> 00:16:59,846 왜냐하면 이러한 모든 조건 새로운 있죠, 전 확실합니다. 413 00:16:59,846 --> 00:17:04,206 조차 위치에 따라서 목록이 표시됩니다 414 00:17:04,206 --> 00:17:08,416 재고 브래킷과 나 닫힌 괄호를 잡고 또는 같음 415 00:17:08,586 --> 00:17:10,716 그리고 어떤 가치 내가 거기에 올리십시오. 416 00:17:10,986 --> 00:17:14,956 지금은 고지도 노력 중이야 오늘, 오늘 0 주 1 417 00:17:14,956 --> 00:17:18,406 주의 같은 조건과 함께 우리가 찾을 수 있기 때문에 동일 418 00:17:18,406 --> 00:17:20,236 이것은 등호 기호 당신이 잘 알고 419 00:17:20,236 --> 00:17:23,546 과 대수학 대부분에서 프로그래밍 언어는 아닙니다 420 00:17:23,546 --> 00:17:26,116 평등, 그것은 평등이 아니야 그것의 숙제. 421 00:17:26,476 --> 00:17:28,936 그것은 무엇에 걸릴 뜻 왼쪽 안에 넣어 422 00:17:28,936 --> 00:17:30,036 왼쪽에있는 것들. 423 00:17:30,266 --> 00:17:32,796 Wait, take what's on the right and put it inside 424 00:17:32,796 ---> 00:17:34,016 of the thing on the left. 425 00:17:34,176 ---> 00:17:35,916 And that's why we've seen this pattern array. 426 00:17:36,226 ---> 00:17:37,766 So this begs an interesting question 427 00:17:37,766 ---> 00:17:39,526 and invites an interesting bug. 428 00:17:39,826 ---> 00:17:41,526 How do you compare two values? 429 00:17:41,646 ---> 00:17:43,376 Is X equal to Y? 430 00:17:43,666 ---> 00:17:46,356 Well, you can't say X equals Y because that would seem 431 00:17:46,356 ---> 00:17:47,666 to put Y's value in X, 432 00:17:47,806 ---> 00:17:50,606 so hopefully there will be a solution to that. 433 00:17:51,416 ---> 00:17:56,646 So with that said, here comes C. when you write a C program, 434 00:17:56,696 ---> 00:17:59,946 as I did on the fly on my Mac last week, recall that I opened 435 00:17:59,946 ---> 00:18:02,496 that like terminal window, it was this little blinking cursor. 436 00:18:02,646 ---> 00:18:05,696 I quickly whipped up the code, the source code, 437 00:18:05,696 ---> 00:18:07,706 at top left there, and then I ran a command. 438 00:18:08,116 ---> 00:18:11,786 Well, trivia what was that command? 439 00:18:12,306 ---> 00:18:14,936 GCC. So this is a term you will not forget after term's end 440 00:18:14,936 ---> 00:18:16,396 because you're going to be running it every day 441 00:18:16,756 ---> 00:18:17,856 that you're tackling problems. 442 00:18:17,856 ---> 00:18:20,176 That's GCC, is a compiler. 443 00:18:20,586 ---> 00:18:21,946 A compiler is a program 444 00:18:22,016 ---> 00:18:23,636 that takes something called source code 445 00:18:23,866 ---> 00:18:25,896 and turns it into object code. 446 00:18:26,016 ---> 00:18:26,816 Now what does that mean? 447 00:18:27,076 ---> 00:18:29,646 Well, nicely enough this course is not 448 00:18:29,706 ---> 00:18:31,886 about writing stuff like this. 449 00:18:32,246 ---> 00:18:34,016 There was a time and there were -- 450 00:18:34,016 ---> 00:18:36,556 there are people still roaming this campus who had 451 00:18:36,556 ---> 00:18:40,746 to essentially write programs at the level of zeros and ones, 452 00:18:40,746 ---> 00:18:42,576 or if you've heard of this thing called a punch card, 453 00:18:42,576 ---> 00:18:44,816 very similar in spirit, and there was a time 454 00:18:44,816 ---> 00:18:48,026 when the science center was a center of science. 455 00:18:48,026 ---> 00:18:49,826 You would go into the basement, you would hand 456 00:18:49,826 ---> 00:18:54,096 in your punch cards and then the person running the mainframe 457 00:18:54,096 ---> 00:18:55,006 computer in the basement 458 00:18:55,006 ---> 00:18:57,496 of the science center would essentially run your homework 459 00:18:57,496 ---> 00:19:00,236 for you overnight, because it would usually take a while, 460 00:19:00,236 ---> 00:19:03,426 by literally putting a stack of cards somewhere into a machine. 461 00:19:03,736 ---> 00:19:05,816 So not the most efficient process, and I've talked 462 00:19:05,816 ---> 00:19:10,356 to current faculty who grew up this way on a campus, 463 00:19:10,586 ---> 00:19:14,416 not the best time of day to find out that your program is buggy, 464 00:19:14,556 ---> 00:19:15,976 it has some mistake in it, right? 465 00:19:15,976 ---> 00:19:17,146 Because that's probably happening 466 00:19:17,146 ---> 00:19:19,646 at 9 a.m. the next morning when you go back to the center 467 00:19:19,646 ---> 00:19:21,996 of science and pick up the results of your program 468 00:19:22,176 ---> 00:19:23,676 and it's just one big error message. 469 00:19:23,676 ---> 00:19:26,676 So fortunately we've come a long way, and all of your fighting 470 00:19:26,676 ---> 00:19:29,426 with bugs and implementing cool things will happen much more 471 00:19:29,426 ---> 00:19:32,316 interactively within seconds in front of your own computer 472 00:19:32,316 ---> 00:19:35,696 or the lab computer, but the process is essentially still 473 00:19:35,696 ---> 00:19:36,126 the same. 474 00:19:36,216 ---> 00:19:39,236 At the end of the day a computer, whether it's a PC 475 00:19:39,236 ---> 00:19:41,016 or a Mac or whatever you guys own at home, 476 00:19:41,326 ---> 00:19:43,596 it only understands 0s and 1s. 477 00:19:43,596 ---> 00:19:46,126 Now the world has done some really clever things with 0s 478 00:19:46,126 ---> 00:19:49,626 and 1s but you still have to turn your programs into 0s 479 00:19:49,626 ---> 00:19:51,966 and 1s and a compiler does exactly that. 480 00:19:52,176 ---> 00:19:54,476 So you'll be writing stuff that looks like this at top left. 481 00:19:54,786 ---> 00:19:57,416 You'll run that file, which is really just a text file, 482 00:19:57,506 ---> 00:19:58,916 through a program called a compiler, 483 00:19:59,116 ---> 00:20:01,556 and that compiler will take care of the task of turning it 484 00:20:01,556 ---> 00:20:03,976 into 0s and 1s like this. 485 00:20:04,886 ---> 00:20:06,016 So where do you do this? 486 00:20:06,016 ---> 00:20:10,116 Well, last week I went ahead and ran this program, 487 00:20:10,116 ---> 00:20:12,136 so just a quick show of hands then we'll have the data 488 00:20:12,136 ---> 00:20:13,856 for sure, how many of you have Macs in the room? 489 00:20:14,036 ---> 00:20:17,106 All right, so that's actually statistically kind of a lot, 490 00:20:17,556 ---> 00:20:19,446 so it looks like more than half of you 491 00:20:19,446 ---> 00:20:21,266 in the room this semester, and that's pretty consistent 492 00:20:21,266 ---> 00:20:24,626 with terms past, what's neat is that all the stuff we're going 493 00:20:24,626 ---> 00:20:25,926 to start doing this week and beyond, 494 00:20:26,176 ---> 00:20:28,706 you actually could have been doing on your own computers, 495 00:20:28,706 ---> 00:20:30,656 your own Macs, this whole time. 496 00:20:30,656 ---> 00:20:33,156 Now terminal is not a program that's usually 497 00:20:33,386 ---> 00:20:35,676 in the little dock here as it is in mine 498 00:20:35,676 ---> 00:20:38,006 because most users don't need to know or care 499 00:20:38,006 ---> 00:20:39,016 about this little terminal. 500 00:20:39,276 ---> 00:20:40,796 But you may at least know anecdotally 501 00:20:40,796 ---> 00:20:42,986 that Mac OS these days is based 502 00:20:42,986 ---> 00:20:44,576 on an operating system called UNIX. 503 00:20:44,796 ---> 00:20:48,626 And back in the day UNIX was essentially a command line 504 00:20:48,686 ---> 00:20:51,096 interface, CLI is the buzzword there, 505 00:20:51,096 ---> 00:20:54,356 and this means you don't double click on icons to run programs, 506 00:20:54,586 ---> 00:20:57,106 you don't go to pretty menus that have sub menus 507 00:20:57,106 ---> 00:20:59,806 and graphical icons and all of this fanciness that developed 508 00:20:59,806 ---> 00:21:02,186 over the years, you if you want to run a program, 509 00:21:02,396 ---> 00:21:04,796 you type the name of the program and hit enter. 510 00:21:05,026 ---> 00:21:07,726 And if you want to influence the behavior of that program, 511 00:21:07,726 ---> 00:21:11,216 you provide it with commands line argument, words or numbers 512 00:21:11,486 ---> 00:21:13,736 after the program's name, and then hit enter. 513 00:21:13,736 ---> 00:21:16,246 If you've ever seen DOS on a computer back home, 514 00:21:16,416 ---> 00:21:17,746 it's very similar in spirit. 515 00:21:17,826 ---> 00:21:20,636 Usually a black screen, white text, and you can't do much 516 00:21:20,706 ---> 00:21:23,926 of interest with it unless you know what's there underneath. 517 00:21:23,926 ---> 00:21:26,226 So you're not going to write for the most part programs 518 00:21:26,226 ---> 00:21:29,746 in this course on your own Macs or on your own PCs per se, 519 00:21:29,966 ---> 00:21:34,346 because it's quite hard for us to standardize the configuration 520 00:21:34,346 ---> 00:21:36,176 of 300 plus people's laptops. 521 00:21:36,406 ---> 00:21:38,276 So instead what we do is provide everyone 522 00:21:38,276 ---> 00:21:40,676 with a uniform environment throughout the semester. 523 00:21:40,926 ---> 00:21:42,936 Initially this is a cluster 524 00:21:43,146 ---> 00:21:48,036 of servers called nice.fas.harvard.edu. 525 00:21:48,106 ---> 00:21:50,246 And this nice cluster does so happen to live 526 00:21:50,246 ---> 00:21:52,306 in this very idyllic building here. 527 00:21:52,646 ---> 00:21:54,246 So it's in the basement, unfortunately, 528 00:21:54,246 ---> 00:21:55,206 the cluster of servers. 529 00:21:55,206 ---> 00:21:57,216 It's also a bit of a misnomer 530 00:21:57,216 ---> 00:22:01,366 because NICE new instructional computing environments has been 531 00:22:01,446 ---> 00:22:05,486 NICE for about 10 years now, and there isn't even an old version 532 00:22:05,486 ---> 00:22:07,846 so they've kind of painted themselves into a corner here. 533 00:22:07,906 ---> 00:22:10,006 We're using the same NICE cluster as always. 534 00:22:10,006 ---> 00:22:13,416 So nice.fas.harvard.edu, it's not a website, 535 00:22:13,416 ---> 00:22:15,906 it's not something you type into a browser, but it's going 536 00:22:15,906 ---> 00:22:18,966 to be the name of a server that you access by way 537 00:22:18,966 ---> 00:22:21,766 of your own Mac or by way of your own PC. 538 00:22:21,766 ---> 00:22:22,686 Well, what do I mean by that? 539 00:22:23,086 ---> 00:22:26,216 well, a lot of you these days have college.harvard.edu 540 00:22:26,216 ---> 00:22:28,776 addresses, but you also have the so-called FAS accounts, 541 00:22:28,776 ---> 00:22:31,756 and these are the user names and passwords you use to login 542 00:22:31,756 ---> 00:22:34,276 to the basement of the science center, kiosks and all of that, 543 00:22:34,396 ---> 00:22:36,186 frankly it will be a few more years, I think, 544 00:22:36,186 ---> 00:22:38,336 before the university converges on just one account. 545 00:22:38,586 ---> 00:22:40,326 But for now you have these accounts, though they're 546 00:22:40,326 ---> 00:22:41,536 of decreasing utility. 547 00:22:41,926 ---> 00:22:44,256 But for this course at least at the start 548 00:22:44,256 ---> 00:22:48,446 of the semester we do acquaint you with nice.fas.harvard.edu 549 00:22:48,446 ---> 00:22:49,316 because what it means is 550 00:22:49,316 ---> 00:22:52,846 that after the semester you'll actually still have a Linux 551 00:22:52,846 ---> 00:22:56,276 server environment on which you can run and write code, 552 00:22:56,276 ---> 00:22:58,896 whether it's for an economic class in the further 553 00:22:58,896 ---> 00:23:00,646 or a chemistry project or anything 554 00:23:00,646 ---> 00:23:03,326 where you need the ability to write programs and you're not 555 00:23:03,376 ---> 00:23:05,636 in CS-50 anymore, you'll at least have this resource 556 00:23:05,636 ---> 00:23:08,046 for some number for a good amount of time. 557 00:23:08,416 ---> 00:23:10,656 What we will start using mid-semester, though, 558 00:23:10,826 ---> 00:23:12,896 and this is the extent of my Photoshop ability, 559 00:23:13,316 ---> 00:23:15,596 we will use the so-called Cloud. 560 00:23:15,686 ---> 00:23:17,786 So this is another one of these buzzwords these days, 561 00:23:17,836 ---> 00:23:20,316 Cloud computing refers to the ability 562 00:23:20,316 ---> 00:23:23,636 to rent server space somewhere out there on the Internet, 563 00:23:23,636 ---> 00:23:27,236 you don't know or care who or where the servers are 564 00:23:27,236 ---> 00:23:28,676 or who is running these servers. 565 00:23:28,956 ---> 00:23:31,176 So we're essentially going to implement this same idea. 566 00:23:31,176 ---> 00:23:33,356 CS-50 has its own cluster of servers now 567 00:23:33,356 ---> 00:23:35,876 in the computer science building called Maxwell Dworkin 568 00:23:35,876 ---> 00:23:36,096 [sounds like]. 569 00:23:36,096 ---> 00:23:38,426 We've got a couple of really big Dell servers 570 00:23:38,426 ---> 00:23:41,596 that have a whole lot of CPUs, 32 gigabytes of RAM inside 571 00:23:41,596 ---> 00:23:43,446 of them, 6 terabytes of storage space. 572 00:23:43,866 ---> 00:23:46,346 So we can hold our own against HCS here. 573 00:23:46,516 ---> 00:23:47,466 We have a couple of those. 574 00:23:47,466 ---> 00:23:49,866 We have an Apple X Serve and long story short all 575 00:23:49,866 ---> 00:23:52,336 of this stuff is wired together in such a way 576 00:23:52,336 ---> 00:23:54,666 that soon this semester you will have your own accounts 577 00:23:54,976 ---> 00:23:59,976 on cloud.cs50.net, and what this will mean is you'll start using 578 00:23:59,976 ---> 00:24:02,596 at some point this cluster instead of nice.fas 579 00:24:03,166 ---> 00:24:04,376 but it's really the same thing. 580 00:24:04,376 ---> 00:24:05,586 Now what do I mean by cluster? 581 00:24:05,936 ---> 00:24:08,356 In the basement of the science center, and also in the basement 582 00:24:08,356 ---> 00:24:10,396 of Maxwell Dworkin, there's a bunch of computers. 583 00:24:10,466 ---> 00:24:12,766 They're all networked together using Ethernet cables 584 00:24:12,766 ---> 00:24:13,816 into a thing called a switch. 585 00:24:14,106 ---> 00:24:18,866 They are exposed publicly on the Internet by way of IP address 586 00:24:18,866 ---> 00:24:21,596 or these names, nice.fas.harvard.edu, 587 00:24:22,056 ---> 00:24:25,316 and there is this illusion that when you connect to one 588 00:24:25,316 ---> 00:24:27,466 of these servers you're connecting to just one, 589 00:24:27,656 ---> 00:24:29,886 but in fact there's like six computers 590 00:24:29,916 ---> 00:24:32,896 in this nice.fas cluster, but they've set them up in 591 00:24:32,896 ---> 00:24:34,856 such a way that you the user don't know or care 592 00:24:34,856 ---> 00:24:35,946 which particular one you're 593 00:24:35,946 ---> 00:24:39,646 on because your files are all visible on any one 594 00:24:39,646 ---> 00:24:41,006 of those machines and all 595 00:24:41,006 ---> 00:24:43,046 of the commands are identical across the same. 596 00:24:43,326 ---> 00:24:46,746 So when it comes time to tackle PSET 1, what you're going to do 597 00:24:46,746 ---> 00:24:48,736 if you're a Mac person is something like this, 598 00:24:48,946 ---> 00:24:50,516 I just ran the terminal program, 599 00:24:50,936 ---> 00:24:52,576 I'm going to type a command called SSH. 600 00:24:52,666 ---> 00:24:54,786 This stands for Secure Shell, 601 00:24:54,786 ---> 00:24:57,226 and this just means make an encrypted connection 602 00:24:57,226 ---> 00:25:00,646 between my laptop, wherever I am in the world, and this server. 603 00:25:00,836 ---> 00:25:04,546 And so what I'm going to do is type SSH.nice let's do Malan 604 00:25:04,646 ---> 00:25:07,426 at nice.fas.harvard.edu. 605 00:25:07,426 ---> 00:25:10,966 I'm going to get a prompt then, looks like I am indeed connected 606 00:25:10,966 ---> 00:25:12,266 to Harvard University server. 607 00:25:12,306 ---> 00:25:13,646 It's asking me for a password. 608 00:25:13,816 ---> 00:25:16,436 Fortunately it won't show you on the screen what the password is 609 00:25:16,496 ---> 00:25:18,576 but now I'm at the so-called blinking prompt 610 00:25:18,846 ---> 00:25:20,056 that these days no longer blinks 611 00:25:20,276 ---> 00:25:21,906 but a blinking prompt it once was. 612 00:25:22,246 ---> 00:25:24,096 So I apparently have three unread messages, 613 00:25:24,196 ---> 00:25:26,496 which has been some time since I never check this email 614 00:25:26,536 ---> 00:25:27,296 account anymore. 615 00:25:27,556 ---> 00:25:29,316 So Malan at nice and then there's this thing 616 00:25:29,316 ---> 00:25:30,066 in parentheses. 617 00:25:30,206 ---> 00:25:32,426 Well this is the command line, so to speak, 618 00:25:32,426 ---> 00:25:34,216 where you can type anything you want. 619 00:25:34,536 ---> 00:25:36,956 Well, that command was found. 620 00:25:37,566 ---> 00:25:40,046 And this is where initially we're going to be writing things 621 00:25:40,086 ---> 00:25:42,406 like C source code and compiling it. 622 00:25:42,806 ---> 00:25:44,496 So what does that mean exactly? 623 00:25:44,496 ---> 00:25:46,536 Well I'm going to do the following just 624 00:25:46,536 ---> 00:25:48,396 to give you a sense of some basics and all 625 00:25:48,396 ---> 00:25:52,666 of this realize will be repeated in problem set 1 own PDF. 626 00:25:52,826 ---> 00:25:55,266 So your hand will be held certainly early in the semester 627 00:25:55,376 ---> 00:25:56,956 so you needn't try to memorize or scribble 628 00:25:56,956 ---> 00:25:58,836 down all these commands but just to give you a sense 629 00:25:58,836 ---> 00:26:01,326 of what we're doing here, if I type the command LS, 630 00:26:01,576 ---> 00:26:04,816 this is list, this means list the files in this directory, 631 00:26:04,816 ---> 00:26:06,816 this folder, well there's nothing there. 632 00:26:07,096 ---> 00:26:09,756 So when I'm at this prompt it's equivalent conceptually 633 00:26:09,756 ---> 00:26:12,816 to being inside of a folder on your own Mac or your own PC, 634 00:26:12,936 ---> 00:26:15,266 it's just graphically very underwhelming. 635 00:26:15,266 ---> 00:26:16,866 And it's more mechanical at the keyboard 636 00:26:16,866 ---> 00:26:18,046 than it is mouse oriented. 637 00:26:18,286 ---> 00:26:21,246 If I want to make a directory called CS-50 for the duration 638 00:26:21,246 ---> 00:26:24,556 of the semester, MKDIR is make directory. 639 00:26:24,836 ---> 00:26:27,006 Back in the day people didn't like to write long commands, 640 00:26:27,106 ---> 00:26:30,306 pretty reasonable, so it's just MKDIR CS-50 hit enter, 641 00:26:30,536 ---> 00:26:34,686 nothing seems to happen but if I type LS now for list notice aha, 642 00:26:34,686 ---> 00:26:36,336 there's a directory as implied 643 00:26:36,336 ---> 00:26:38,476 by the slash there, that's called CS-50. 644 00:26:38,756 ---> 00:26:41,176 Well, I can't, unfortunately, it's a little blue 645 00:26:41,176 ---> 00:26:44,576 on this screen here but that indeed says CS-50 if I type LS. 646 00:26:45,186 ---> 00:26:48,596 Notice that I can't, and this is kind of a neophyte mistake, 647 00:26:48,596 ---> 00:26:51,236 can't really double click and nothing really happens there 648 00:26:51,396 ---> 00:26:56,136 so you have to change directory CD into CS-50 and then hit enter 649 00:26:56,376 ---> 00:26:58,926 and now my parentheses, this is just a special feature 650 00:26:58,926 ---> 00:27:01,266 of the way we've configured your accounts, you'll see. 651 00:27:01,536 ---> 00:27:03,786 This just reminds you where you are, which is nice 652 00:27:03,786 ---> 00:27:06,116 when you start to have lots of folders open. 653 00:27:06,456 ---> 00:27:09,996 Now if I type in LS here there's nothing here, so if I want 654 00:27:09,996 ---> 00:27:13,106 to write my first program I need to open a text editor 655 00:27:13,106 ---> 00:27:16,266 and the text editor that we'll encourage most students 656 00:27:16,266 ---> 00:27:18,336 to use is this little program called NANO. 657 00:27:18,706 ---> 00:27:22,366 If you've ever used notepad on PCs or text edit on Macs, 658 00:27:22,766 ---> 00:27:25,586 this is like the most user friendly text editor you can 659 00:27:25,586 ---> 00:27:27,996 find but as such it's also lacking a number 660 00:27:27,996 ---> 00:27:29,856 of useful features as some of you 661 00:27:29,856 ---> 00:27:31,116 with more experience will see. 662 00:27:31,376 ---> 00:27:34,456 So let me go ahead and write hello.c. Notice 663 00:27:34,526 ---> 00:27:36,866 that I have just a simple window. 664 00:27:37,056 ---> 00:27:38,466 It's a little cryptic at the bottom, 665 00:27:38,466 ---> 00:27:40,166 but again this is just stupid stuff 666 00:27:40,166 ---> 00:27:41,946 that once you know it you kind of never forget. 667 00:27:42,146 ---> 00:27:44,356 The carrot symbol means hold the control key, 668 00:27:44,626 ---> 00:27:45,856 so we'll get to that in a second. 669 00:27:45,856 ---> 00:27:48,246 But let me go each and recreate really quickly what I did 670 00:27:48,246 ---> 00:27:48,816 last week. 671 00:27:49,096 ---> 00:27:51,266 So I type this cryptic sequence of characters, 672 00:27:51,266 ---> 00:27:55,706 include STDIO.h in angle brackets. 673 00:27:56,056 ---> 00:28:00,936 I then set into main ent arg C char star, 674 00:28:02,156 ---> 00:28:07,196 delete key is not working, we've got to fix that. 675 00:28:07,716 ---> 00:28:09,626 Well, that's interesting. 676 00:28:11,786 ---> 00:28:14,326 Wow. All right, I'm going to do this again 677 00:28:14,326 ---> 00:28:15,736 without making any mistakes. 678 00:28:16,496 ---> 00:28:23,556 Standardio.h ent main ent arg C char star, here it comes, 679 00:28:23,606 ---> 00:28:28,916 arg v bracket parentheses open curly brace 1234 Print F 680 00:28:28,916 ---> 00:28:31,486 and I'm just going to say hello, world. 681 00:28:31,486 ---> 00:28:34,386 I'm going to make it look pretty at the end with the backslash n, 682 00:28:34,536 ---> 00:28:37,126 closed parentheses, semicolon, close. 683 00:28:37,126 ---> 00:28:39,996 Okay. we're not going to indent properly here we go, 684 00:28:41,086 ---> 00:28:41,526 closed brace. 685 00:28:41,656 ---> 00:28:43,076 So that's my first C program, 686 00:28:43,076 ---> 00:28:45,246 and this is the thing we completely underwhelmed you 687 00:28:45,246 ---> 00:28:45,956 with last week. 688 00:28:45,956 ---> 00:28:47,396 But what does this mean I'm going to do now? 689 00:28:47,396 ---> 00:28:49,106 I'm going to hit control X 690 00:28:49,176 ---> 00:28:51,686 because down here it said carrot X for exit 691 00:28:52,016 ---> 00:28:53,966 so now it's saying save modified buffer. 692 00:28:54,146 ---> 00:28:55,626 This is the un-user friendly way 693 00:28:55,626 ---> 00:28:57,356 of saying do you want to save your changes? 694 00:28:57,576 ---> 00:28:58,636 I hit Y for yes. 695 00:28:58,746 ---> 00:29:01,326 It then checks what name do you want to give this file? 696 00:29:01,326 ---> 00:29:03,086 Again it's just reminding me what it's already called 697 00:29:03,086 ---> 00:29:03,986 in case I want to change it. 698 00:29:03,986 ---> 00:29:06,596 I hit enter and voila, I'm back at the prompt. 699 00:29:06,806 ---> 00:29:09,446 But if I now type LS what should I see? 700 00:29:10,196 ---> 00:29:12,656 Hopefully hello.c and this time it's all white 701 00:29:12,726 ---> 00:29:15,346 because it's not a directory so now I need to run this thing, 702 00:29:15,566 ---> 00:29:19,056 so I could try doing hello.c or again the newbie mistake 703 00:29:19,056 ---> 00:29:21,296 of really that's not going to do anything, 704 00:29:21,616 ---> 00:29:23,726 hit enter, permission denied. 705 00:29:23,936 ---> 00:29:26,316 But that makes sense because what's inside this file? 706 00:29:27,086 ---> 00:29:30,396 This is not 0s and 1s clearly, this is just source code. 707 00:29:30,396 ---> 00:29:33,136 So source code is the human readable form of this stuff 708 00:29:33,286 ---> 00:29:36,816 but I remember from last week GCC hello.c. Let me go ahead 709 00:29:36,816 ---> 00:29:40,666 and hit enter now, nothing seems to happen, but wait, LS. 710 00:29:40,956 ---> 00:29:41,486 Interesting. 711 00:29:41,916 ---> 00:29:45,446 Again foolishly named default name for a program anything 712 00:29:45,446 ---> 00:29:48,026 like hello.exe would seem a little more reasonable, 713 00:29:48,256 ---> 00:29:50,586 but a.out is sort of the standard but we'll be able 714 00:29:50,586 ---> 00:29:51,756 to override that soon. 715 00:29:52,056 ---> 00:29:55,836 So a.out has an asterisks which just means I am executable. 716 00:29:55,836 ---> 00:29:57,436 I have 0s and 1s inside of me. 717 00:29:57,436 ---> 00:30:01,076 In fact if I get a little adventurous and now open a.out 718 00:30:01,076 ---> 00:30:03,596 with nano, nano being a text editor, 719 00:30:03,596 ---> 00:30:07,106 a.out being a binary file, binary meaning just 0s 720 00:30:07,106 ---> 00:30:10,526 and 1s inside, so that's the program I wrote. 721 00:30:10,656 ---> 00:30:13,676 Now here's too where you can do very bad things very easily. 722 00:30:13,676 ---> 00:30:16,556 If you so much as hit the space bar accidentally 723 00:30:16,556 ---> 00:30:18,496 as you're flailing about in the basement 724 00:30:18,496 ---> 00:30:19,236 of the science center trying 725 00:30:19,236 ---> 00:30:20,946 to fix whatever problem you've just created, 726 00:30:21,186 ---> 00:30:23,936 you just inserted aski characters, 727 00:30:23,936 ---> 00:30:26,556 random text into what's otherwise a binary file. 728 00:30:26,806 ---> 00:30:28,466 Why does this look so cryptic? 729 00:30:28,746 ---> 00:30:30,406 Well, nano is again a text editor. 730 00:30:30,406 ---> 00:30:34,466 It doesn't know -- it's not supposed to show you 0s and 1s. 731 00:30:34,696 ---> 00:30:37,646 It's supposed to show you the letters and the numbers 732 00:30:37,646 ---> 00:30:40,296 and the punctuation that those 0s and 1s represent. 733 00:30:40,566 ---> 00:30:42,916 So when you see all this crazy stuff on the screen, 734 00:30:43,136 ---> 00:30:45,276 that's just nano's misinterpretation 735 00:30:45,476 ---> 00:30:48,796 of what's really 0s and 1s, not necessarily aski letters. 736 00:30:49,006 ---> 00:30:51,086 Fortunately control X will save me here, 737 00:30:51,086 ---> 00:30:53,096 save modified buffer, no this time. 738 00:30:53,356 ---> 00:30:55,236 So I hit N, I go back to the prompt 739 00:30:55,416 ---> 00:30:58,776 and now I can run a.out just by typing this command here 740 00:30:58,776 ---> 00:31:02,446 and in fact that's my first repeated C program. 741 00:31:02,806 ---> 00:31:03,356 So that's it. 742 00:31:03,356 ---> 00:31:05,606 that's the basic building block of writing a C program. 743 00:31:05,666 ---> 00:31:08,706 Hopefully we can do much more interesting things than that 744 00:31:09,146 ---> 00:31:10,826 but that covers the basic workflow. 745 00:31:10,826 ---> 00:31:12,766 Now just to give you a sense that what we're doing 746 00:31:12,766 ---> 00:31:16,336 in this course is ultimately pretty much operating system 747 00:31:16,336 ---> 00:31:20,246 agnostic, here we have Mac, here we have PC, running Mac OS, 748 00:31:20,246 ---> 00:31:23,246 running Windows, on the Windows world it's not quite as easy 749 00:31:23,246 ---> 00:31:25,886 as going to a terminal window because Windows does not ship 750 00:31:25,966 ---> 00:31:28,616 with that little program called SSH 751 00:31:28,616 ---> 00:31:31,366 with which I created the secure connection, but there's plenty 752 00:31:31,366 ---> 00:31:32,776 of free tools that do that. 753 00:31:33,166 ---> 00:31:33,866 One thing you'll see 754 00:31:33,866 ---> 00:31:35,876 on the course's website is program called putty. 755 00:31:35,966 ---> 00:31:38,666 So if you're a PC user you run a program 756 00:31:38,666 ---> 00:31:41,306 like this it's a little more user friendly if overwhelming 757 00:31:41,306 ---> 00:31:42,296 with all of its options. 758 00:31:42,546 ---> 00:31:44,846 What I'm simply going to do here is say, you know what, 759 00:31:44,846 ---> 00:31:48,196 I want to connect to nice.Fas.harvard.edu. 760 00:31:48,466 ---> 00:31:50,666 so if I were doing this for the first time I would simply do 761 00:31:50,666 ---> 00:31:54,066 something like that, typing in its host name or its IP address. 762 00:31:54,066 ---> 00:31:55,696 Now I'm going to go ahead and click -- 763 00:31:55,866 ---> 00:31:57,666 actually I'm going to load something there 764 00:31:57,716 ---> 00:31:58,806 so I get the bigger font size. 765 00:31:58,806 ---> 00:32:02,296 I'm going to click open and now I get this black window again. 766 00:32:02,296 ---> 00:32:03,566 I'm going to log in as Malan. 767 00:32:03,696 ---> 00:32:07,526 I get a similar prompt, enter, notice I'm back in here. 768 00:32:07,526 ---> 00:32:10,606 if I type LS there's CS-50, CD CS-50, aha, 769 00:32:10,606 ---> 00:32:11,996 there's my a.out program. 770 00:32:12,536 ---> 00:32:13,386 Same exact thing. 771 00:32:13,586 ---> 00:32:14,906 So this is actually powerful. 772 00:32:14,906 ---> 00:32:17,096 Even though I'm on a PC here, a Mac over there, 773 00:32:17,216 ---> 00:32:20,466 I've accessed the same account so that's one of the upsides 774 00:32:20,466 ---> 00:32:21,746 of having this central server. 775 00:32:21,746 ---> 00:32:23,856 You'll be able to access your code anywhere. 776 00:32:23,856 ---> 00:32:26,116 If you go home on break, if you get sick, if you're just hanging 777 00:32:26,116 ---> 00:32:28,566 out a friend's you can access your code in this course 778 00:32:28,896 ---> 00:32:31,106 from any computer on the Internet and you'll find 779 00:32:31,266 ---> 00:32:33,676 that for better or for worse to be at least useful. 780 00:32:33,856 ---> 00:32:35,876 So just to give you a sense of what else you can do 781 00:32:36,126 ---> 00:32:40,136 on a typical Linux server, so the machine I connected to, 782 00:32:40,166 ---> 00:32:42,016 nice.fas, it's running at Linux, 783 00:32:42,336 ---> 00:32:45,306 which is again an operating system that's larger text-based 784 00:32:45,716 ---> 00:32:49,246 but there are goes, graphical user interfaces, 785 00:32:49,426 ---> 00:32:51,006 and in fact if you headed to the basement 786 00:32:51,006 ---> 00:32:53,206 of the science center someday as you might for office hours, 787 00:32:53,466 ---> 00:32:56,196 they've got like 33 percent Linux computers 788 00:32:56,196 ---> 00:32:56,976 in the basement there. 789 00:32:57,256 ---> 00:32:59,326 they do have Windows, they do have menus, 790 00:32:59,376 ---> 00:33:01,306 things you can click, because the world has come 791 00:33:01,306 ---> 00:33:03,596 up with more user-friendly interfaces to Linux. 792 00:33:03,826 ---> 00:33:05,786 But you'll get your hands directly this semester with some 793 00:33:05,786 ---> 00:33:08,636 of the building blocks because frankly when you get comfortable 794 00:33:08,636 ---> 00:33:12,026 with this stuff you can do so much more, so much more easily 795 00:33:12,026 ---> 00:33:13,756 and so much more efficiently just 796 00:33:13,756 ---> 00:33:16,216 by telling the computer precisely what you want. 797 00:33:16,216 ---> 00:33:19,226 So CD we saw, CP, any guess? 798 00:33:19,836 ---> 00:33:23,416 CP, copy, kind of the shorthand version of copy, 799 00:33:23,416 ---> 00:33:26,276 and in fact it is, CP we'll use to copy code this semester. 800 00:33:26,276 ---> 00:33:32,186 LS is list, MK-Dir is make directory, MV, move, 801 00:33:32,186 ---> 00:33:35,826 so that's synonymous, we'll see renaming a file, 802 00:33:35,826 ---> 00:33:39,846 so to rename a file you'll say MV space the original name space 803 00:33:39,936 ---> 00:33:43,206 the new name, not terribly hard. 804 00:33:43,896 ---> 00:33:45,856 PWD. Yeah, so print working directory. 805 00:33:45,856 ---> 00:33:48,726 What this means here is I'm back on the nice.fas server. 806 00:33:48,906 ---> 00:33:50,946 If I kind of get a little confused sometime 807 00:33:50,946 ---> 00:33:55,596 and I type PWD it will tell me the full path to where I am 808 00:33:55,596 ---> 00:33:58,446 on the server, so right now I'm logged in as Malan 809 00:33:58,486 ---> 00:34:01,096 and Malan does not have access to everything on the server 810 00:34:01,096 ---> 00:34:04,156 because there's like 20,000 other people with fas accounts. 811 00:34:04,486 ---> 00:34:07,096 So in fact, fas took the approach years ago, 812 00:34:07,096 ---> 00:34:08,066 very intelligently, 813 00:34:08,256 ---> 00:34:10,196 of organizing things hierarchically. 814 00:34:10,456 ---> 00:34:11,936 So notice there's a directory, 815 00:34:11,976 ---> 00:34:14,716 the root of the hard drive apparently has a directory 816 00:34:14,716 ---> 00:34:17,616 in it called NFS, network file system, home, 817 00:34:17,616 ---> 00:34:19,826 which is where everyone's home directories live. 818 00:34:19,826 ---> 00:34:22,066 And a home directory is just your personal storage space. 819 00:34:22,586 ---> 00:34:25,756 M/A just looks like there's a whole hierarchy of names there 820 00:34:25,756 ---> 00:34:28,536 to keep things clean, slash CS-50, this is the full path 821 00:34:28,866 ---> 00:34:32,516 to where I am, and realize that I can definitely go poking 822 00:34:32,516 ---> 00:34:33,616 around if I get curious. 823 00:34:33,616 ---> 00:34:34,716 This is not a bad thing. 824 00:34:34,716 ---> 00:34:39,216 If I type CD DOT DOT it doesn't go this way it goes backwards 825 00:34:39,216 ---> 00:34:41,846 so to speak or higher up in this tree, so now notice I'm back 826 00:34:41,956 ---> 00:34:43,326 in my so-called home directory. 827 00:34:43,676 ---> 00:34:46,126 Where am I going to be if I do it once more? 828 00:34:47,496 ---> 00:34:49,316 Yeah, the directory called A. So with all 829 00:34:49,316 ---> 00:34:52,976 of the people whose usernames start with MA, 830 00:34:52,976 ---> 00:34:56,616 which if I do CD it's getting a little curious here. 831 00:34:56,866 ---> 00:34:59,186 Maybe will this backfire? 832 00:34:59,456 ---> 00:35:01,546 Maybe if we could put the camera down here for just a moment 833 00:35:01,546 ---> 00:35:03,306 so that we're not podcasting this to the Internet, 834 00:35:03,556 ---> 00:35:07,056 these are all of the people on fas.harvard.edu whose names, 835 00:35:07,146 ---> 00:35:10,206 sorry folks at home can't see this, that begin with MA. 836 00:35:10,406 ---> 00:35:14,066 If we go back one more directory keep the camera underwhelming 837 00:35:14,216 ---> 00:35:15,796 down here, there's the whole alphabet. 838 00:35:16,036 ---> 00:35:17,376 We can see people that start 839 00:35:17,376 ---> 00:35:22,326 with probably no MZs I'm guessing, CDZ, LS, oh there are. 840 00:35:22,326 ---> 00:35:25,026 So it's not a full name, it's first letter 841 00:35:25,136 ---> 00:35:26,826 of the first name, last name. 842 00:35:26,826 ---> 00:35:29,646 So again you can poke around all you want and see a whole bunch 843 00:35:29,646 ---> 00:35:31,366 of stuff on this computer, but Linux, 844 00:35:31,366 ---> 00:35:33,626 like most operating systems, has various permissions 845 00:35:33,626 ---> 00:35:37,086 and fancy control features so you really can't do bad things. 846 00:35:37,086 ---> 00:35:39,726 you can't access ,for instance, if I get nosy, 847 00:35:39,726 ---> 00:35:44,496 let's say home/a/y idida 848 00:35:44,496 ---> 00:35:46,006 for Jansue's [sounds like] home directory. 849 00:35:46,816 ---> 00:35:55,346 Let me, I'm forgetting the day, so I'm in it. 850 00:35:55,796 ---> 00:35:58,086 Thankfully, permission denied. 851 00:35:58,086 ---> 00:36:00,076 So things are, in fact, configured correctly. 852 00:36:00,306 ---> 00:36:01,826 So again just random little trivia 853 00:36:01,826 ---> 00:36:03,246 that ultimately gets useful 854 00:36:03,246 ---> 00:36:05,276 because just understanding the world 855 00:36:05,276 ---> 00:36:07,366 in which you're playing I think lets you get yourself 856 00:36:07,366 ---> 00:36:09,786 out of problems and actually solve more interesting ones. 857 00:36:10,026 ---> 00:36:11,746 So there are some other commands that we'll see, 858 00:36:11,746 ---> 00:36:14,176 and again every piece that's pdf will walk you 859 00:36:14,236 ---> 00:36:15,366 through any of this minutiae. 860 00:36:15,576 ---> 00:36:17,066 You're not going to have to figure it out or figure 861 00:36:17,066 ---> 00:36:20,446 out from week 1 what the heck was the command for this. 862 00:36:20,446 ---> 00:36:23,846 So we're going to see things like GCC, GDB, 863 00:36:24,046 ---> 00:36:26,996 commands like more and then someone got clever. 864 00:36:26,996 ---> 00:36:28,076 More is just a program 865 00:36:28,076 ---> 00:36:29,686 that shows you the contents of a file. 866 00:36:29,906 ---> 00:36:31,606 Well, someone wanted to be clever and kind of one 867 00:36:31,606 ---> 00:36:33,306 up that person so they'd called their program less 868 00:36:33,626 ---> 00:36:35,366 but it does really the same thing. 869 00:36:35,686 ---> 00:36:39,056 Man for manual, which is something you'll get familiar 870 00:36:39,056 ---> 00:36:39,936 with as well. 871 00:36:40,176 ---> 00:36:42,576 So what does it take to write a program, so it's three steps 872 00:36:42,576 ---> 00:36:43,346 and we've done it twice. 873 00:36:43,346 ---> 00:36:46,546 Last week and this, one, open up a text editor like nano 874 00:36:46,676 ---> 00:36:49,046 in a Linux environment and call the file whatever, 875 00:36:49,146 ---> 00:36:53,866 hi1.c or hello1.c, using the dot C convention for namesake. 876 00:36:54,236 ---> 00:36:56,806 GCC the name of the file and then you run the thing 877 00:36:56,886 ---> 00:36:59,516 by simply running the default name. 878 00:36:59,906 ---> 00:37:02,046 Well, what if we want to do something more interesting, 879 00:37:02,046 ---> 00:37:04,866 give it a non-stupid name like a.out? 880 00:37:05,226 ---> 00:37:07,636 So there are again these things called command line arguments 881 00:37:07,676 ---> 00:37:10,736 or switches with which you can control the behavior 882 00:37:10,736 ---> 00:37:12,586 of code more interestingly. 883 00:37:12,586 ---> 00:37:15,736 So if I go back over here into my CS-50 account, 884 00:37:16,166 ---> 00:37:19,526 my CS-50 directory, here's hello.c. my goal now is 885 00:37:19,526 ---> 00:37:22,416 to create a more interesting name than a.out, 886 00:37:22,776 ---> 00:37:25,856 so per that previous slide I say dash 0 for output. 887 00:37:26,156 ---> 00:37:27,816 Let's call the program hello 888 00:37:28,026 ---> 00:37:31,286 and then let's say compile this particular program, LS. 889 00:37:31,286 ---> 00:37:35,346 Now I have a binary, 0s and 1s called hello up. 890 00:37:35,726 ---> 00:37:39,796 So you'll notice little keystrokes that save you time. 891 00:37:39,796 ---> 00:37:42,526 If you hit tab it will do auto complete which saves you time. 892 00:37:42,776 ---> 00:37:44,766 Unfortunately it also reveals all the other commands 893 00:37:44,766 ---> 00:37:47,926 on the server which start with he, in this case head, hello, 894 00:37:47,926 ---> 00:37:50,316 help desk, help desk server, help z tags and [inaudible], 895 00:37:50,546 ---> 00:37:54,636 none of which I care about so hello, enter, 896 00:37:54,766 ---> 00:37:56,996 same exact program even though it's called something 897 00:37:56,996 ---> 00:37:57,606 different still. 898 00:37:57,606 ---> 00:38:00,366 So more interesting but again just a fundamentally 899 00:38:00,366 ---> 00:38:01,586 uninteresting building block. 900 00:38:01,736 ---> 00:38:04,056 But your programs are going to get more complicated over time. 901 00:38:04,296 ---> 00:38:06,846 Most of your programs by semester's end are not going 902 00:38:06,846 ---> 00:38:09,456 to be this big in a simple text file, 903 00:38:09,736 ---> 00:38:11,196 they're going to be multiple files. 904 00:38:11,196 ---> 00:38:12,896 And they're not going to be terribly long each, 905 00:38:12,896 ---> 00:38:14,936 but we'll see one of the principals we'll preach 906 00:38:14,936 ---> 00:38:17,316 in the course is design, and good design, 907 00:38:17,546 ---> 00:38:20,116 and as some of you may have experienced in scratch already, 908 00:38:20,746 ---> 00:38:23,266 if you're implementing a script that's kind of this big 909 00:38:23,266 ---> 00:38:25,106 and then you add some more features and then it's this big 910 00:38:25,106 ---> 00:38:27,566 and then this big and this big and God forbid this wide 911 00:38:27,566 ---> 00:38:30,646 and wide and wide because you keep adding ifs and its and ifs 912 00:38:30,646 ---> 00:38:33,706 and its you're probably crossing the boundary at some point 913 00:38:33,706 ---> 00:38:35,596 of what we'd call good design. 914 00:38:35,596 ---> 00:38:37,486 If you're scrolling up, down, left right just 915 00:38:37,486 ---> 00:38:40,416 to see your own program there's probably a better approach. 916 00:38:40,416 ---> 00:38:43,256 Now for PSET 0, they don't need to worry so much about this 917 00:38:43,256 ---> 00:38:45,336 because we haven't really told you what good design is, 918 00:38:45,636 ---> 00:38:48,596 but among the features will be chopping up your code 919 00:38:48,596 ---> 00:38:50,936 into much more manageable bite-sized pieces, 920 00:38:50,986 ---> 00:38:53,146 putting it in separate files, putting it in scratch 921 00:38:53,146 ---> 00:38:55,436 in separate scripts, and you'll see that a command 922 00:38:55,436 ---> 00:38:57,626 that will facilitate this is called make. 923 00:38:57,886 ---> 00:39:00,316 So you'll see both of these approaches in PSET 1, 924 00:39:00,566 ---> 00:39:03,766 simply typing Make and then the name of the program you want 925 00:39:03,826 ---> 00:39:05,876 to make, in this case, hello. 926 00:39:05,876 ---> 00:39:08,966 Notice I'm not typing DOT C, I'm saying make hello. 927 00:39:09,236 ---> 00:39:11,636 Make is a program that's going to infer, well, 928 00:39:11,636 ---> 00:39:13,806 if this guy wants to make a program called make it's 929 00:39:13,856 ---> 00:39:16,216 probably based on a file called make.c 930 00:39:16,476 ---> 00:39:20,566 so if I hit enter it tried to recompile it but it realized -- 931 00:39:20,566 ---> 00:39:22,646 and this is what's cool about make -- it realized, oh, 932 00:39:22,686 ---> 00:39:23,776 you haven't changed the program, 933 00:39:23,776 ---> 00:39:27,316 why should I waste my time regenerated identical 0s and 1s. 934 00:39:27,626 ---> 00:39:29,046 So in fact it didn't bother. 935 00:39:29,226 ---> 00:39:33,016 But if I do LS to see my files how do I remove hello and a.out? 936 00:39:34,146 ---> 00:39:37,916 Yeah, rm, hello, enter, it's going to ask for a sanity check. 937 00:39:37,916 ---> 00:39:39,786 Remove regular file hello question mark? 938 00:39:39,786 ---> 00:39:42,826 Yes. RM a.out, yes for that too. 939 00:39:42,826 ---> 00:39:46,426 So now I just have my source code, make hello enter, 940 00:39:46,646 ---> 00:39:49,496 so the command's going to look a little more cryptic because we, 941 00:39:49,496 ---> 00:39:51,206 just to get you started at term start, 942 00:39:51,296 ---> 00:39:53,086 are configuring these accounts in a way 943 00:39:53,086 ---> 00:39:54,666 that just makes some things easier 944 00:39:54,666 ---> 00:39:56,666 and we'll take those training wheels off over time, 945 00:39:56,936 ---> 00:39:58,806 but it achieves the same results because I now 946 00:39:58,806 ---> 00:40:02,296 in fact have a program called hello in that directory as well. 947 00:40:02,616 ---> 00:40:04,606 So what are these programs you can use? 948 00:40:04,606 ---> 00:40:07,686 So nano is by far the simplest editor you can use 949 00:40:07,686 ---> 00:40:08,786 at least at term start. 950 00:40:09,026 ---> 00:40:11,596 On my computer it doesn't support the delete feature 951 00:40:11,596 ---> 00:40:14,016 but we will fix that so that you don't need 952 00:40:14,016 ---> 00:40:17,486 to fail the very first time you make a program like I did, 953 00:40:17,746 ---> 00:40:19,116 but there are other tools out there. 954 00:40:19,116 ---> 00:40:21,646 Those of you might know programs like VIM and in fact most 955 00:40:21,646 ---> 00:40:24,446 of the time I'll use a program called VIM just 956 00:40:24,446 ---> 00:40:26,516 because that's what I was taught in CS-50 years ago. 957 00:40:26,516 ---> 00:40:27,556 I kind of grew up on it. 958 00:40:27,766 ---> 00:40:30,816 EMAX is another popular one, but more on this in the future. 959 00:40:30,816 ---> 00:40:33,446 I mention it now only so that you don't get confused 960 00:40:33,446 ---> 00:40:35,776 or puzzled when you see this TF used this program, 961 00:40:35,936 ---> 00:40:36,736 this TF used another. 962 00:40:37,016 ---> 00:40:40,126 It's just like using pages versus Microsoft Word 963 00:40:40,126 ---> 00:40:42,936 versus Word Pad, it's all the same kind of stuff 964 00:40:42,936 ---> 00:40:43,946 in this world as well. 965 00:40:44,256 ---> 00:40:45,366 So in a moment we're going 966 00:40:45,436 ---> 00:40:47,236 to actually tease apart what it means 967 00:40:47,236 ---> 00:40:49,626 to write a more interesting program than hello world. 968 00:40:49,626 ---> 00:40:52,756 The basic building block for almost any C program is going 969 00:40:52,756 ---> 00:40:55,766 to start with this construct here, but why don't we go ahead 970 00:40:55,766 ---> 00:40:56,896 since this is a lot to digest, 971 00:40:57,096 ---> 00:40:58,326 and take a five minute break first. 972 00:41:05,486 ---> 00:41:06,456 All right. 973 00:41:06,876 ---> 00:41:08,826 We are back, so Yuki [assumed spelling] 974 00:41:08,826 ---> 00:41:09,966 and Jantsu [assumed spelling] informed me 975 00:41:09,966 ---> 00:41:12,186 that sectioning will indeed debut this evening, 976 00:41:12,186 ---> 00:41:13,846 go to CS-50.net, take a look 977 00:41:13,846 ---> 00:41:15,966 at any instructions you'll find on the home page. 978 00:41:15,966 ---> 00:41:18,076 Check around midnight or certainly by morning, 979 00:41:18,416 ---> 00:41:21,026 and note this, so per last week's announcements 980 00:41:21,026 ---> 00:41:23,826 in the syllabus we do offer three tracks of sections, 981 00:41:23,826 ---> 00:41:27,146 just like First Nights does for our students who are more 982 00:41:27,146 ---> 00:41:29,566 and less comfortable with music, so we do the same. 983 00:41:29,566 ---> 00:41:32,136 It's just the idea of being in CS-50, 984 00:41:32,386 ---> 00:41:34,106 so there's no steadfast rule 985 00:41:34,106 ---> 00:41:36,056 as to what makes you less comfortable, 986 00:41:36,056 ---> 00:41:37,316 what makes you more comfortable 987 00:41:37,316 ---> 00:41:38,746 and what makes you somewhere in between. 988 00:41:39,036 ---> 00:41:41,036 To be honest, it's a term you can probably just slap 989 00:41:41,036 ---> 00:41:43,606 on yourself based on just how comfortable you actually are 990 00:41:43,826 ---> 00:41:46,396 having returned this week to CS-50. 991 00:41:46,396 ---> 00:41:48,616 You've seen what the percentage break-downs are so we get plenty 992 00:41:48,616 ---> 00:41:49,776 of folks from each of the buckets, 993 00:41:50,036 ---> 00:41:51,946 so when you use fas's sectioning tool, 994 00:41:52,226 ---> 00:41:54,346 realize that because we have these three different types 995 00:41:54,346 ---> 00:41:56,206 of sections you're going to see a long list 996 00:41:56,206 ---> 00:41:57,616 of about 30 sections, since we have 997 00:41:57,616 ---> 00:41:59,756 about 30 teaching fellows and thus 30 sections. 998 00:41:59,976 ---> 00:42:01,336 and in the comments fields 999 00:42:01,336 ---> 00:42:03,116 of the sectioning program you'll see 1000 00:42:03,116 ---> 00:42:05,086 if that section slot has been designated 1001 00:42:05,086 ---> 00:42:06,946 for those more comfortable, those less 1002 00:42:07,246 ---> 00:42:08,586 or those somewhere in between. 1003 00:42:08,846 ---> 00:42:09,776 If you're on the fence as to 1004 00:42:09,776 ---> 00:42:12,476 where you belong you cannot go wrong being 1005 00:42:12,476 ---> 00:42:14,016 in the somewhere in between section. 1006 00:42:14,016 ---> 00:42:16,146 That's really for folks that just don't feel themselves 1007 00:42:16,146 ---> 00:42:19,256 at either extreme, but certainly feel free to chat with me or any 1008 00:42:19,256 ---> 00:42:20,576 of the TFs if you're curious 1009 00:42:20,576 ---> 00:42:23,336 as to what this all means or where you belong. 1010 00:42:23,336 ---> 00:42:25,206 Now what does this mean in real terms for sections? 1011 00:42:25,896 ---> 00:42:27,486 Frankly it just means that especially 1012 00:42:27,486 ---> 00:42:29,906 for those less comfortable, it just means you're going to be 1013 00:42:29,906 ---> 00:42:33,406 in a room full of people who feel as apprehensive 1014 00:42:33,406 ---> 00:42:36,656 or as inexperienced as you and it's sort of a safer space 1015 00:42:36,656 ---> 00:42:37,826 in which to put up your hand 1016 00:42:37,826 ---> 00:42:40,416 and ask a question you think is the proverbial dumb question. 1017 00:42:40,716 ---> 00:42:43,106 The sections for those more comfortable are meant 1018 00:42:43,106 ---> 00:42:45,956 to digress intentionally from say the course's syllabus, 1019 00:42:46,266 ---> 00:42:48,196 from the week's problem set and really go off 1020 00:42:48,196 ---> 00:42:50,336 in any interesting technical direction that some 1021 00:42:50,336 ---> 00:42:51,716 of the savvier students might 1022 00:42:51,716 ---> 00:42:54,186 like to explore even though it's not going to help them per se 1023 00:42:54,356 ---> 00:42:55,896 on that particular week's problem set. 1024 00:42:56,036 ---> 00:42:58,296 But again if you don't feel yourself needing that sort 1025 00:42:58,296 ---> 00:43:00,866 of comfort zone here or you don't really think 1026 00:43:00,916 ---> 00:43:02,786 that you'd want to try holding your own with some 1027 00:43:02,786 ---> 00:43:04,836 of those more comfortable then the sweet spot, 1028 00:43:04,836 ---> 00:43:06,776 just like the standard editions for most students is 1029 00:43:06,776 ---> 00:43:08,886 that for those somewhere in between. 1030 00:43:09,276 ---> 00:43:12,246 All right, so let's do something a little more interesting now. 1031 00:43:12,246 ---> 00:43:15,206 I've gone ahead and per the handout you have I have a whole 1032 00:43:15,206 ---> 00:43:17,456 bunch of code already in this account. 1033 00:43:17,456 ---> 00:43:19,246 So I'm going to go back to my screen here 1034 00:43:19,476 ---> 00:43:21,486 and you'll see again commands lli this on PSETs. 1035 00:43:21,486 ---> 00:43:26,066 What I'm going to do for a moment is copy, tilda, CS-50, 1036 00:43:26,276 ---> 00:43:27,956 so henceforth the Tilda character 1037 00:43:27,956 ---> 00:43:29,306 which on most U.S. keyboards is 1038 00:43:29,306 ---> 00:43:33,336 on the top left near the escape key, Tilda CS-50 means go 1039 00:43:33,336 ---> 00:43:35,946 into CS-50's home directory. 1040 00:43:36,116 ---> 00:43:37,996 Now I'm in Malan's home directory at the moment, 1041 00:43:37,996 ---> 00:43:41,916 so go into CS-50 is just like I tried to idida's home directory, 1042 00:43:41,916 ---> 00:43:43,976 so go into CS-50's and then I know 1043 00:43:43,976 ---> 00:43:46,226 because I'm reading this off of a pdf or whatever 1044 00:43:46,426 ---> 00:43:49,526 that there's a pub directory, that there's a source, src, 1045 00:43:49,526 ---> 00:43:51,996 again, nicknames in Linux, source directory, 1046 00:43:51,996 ---> 00:43:54,536 and then I know there's a lectures directory in there 1047 00:43:54,536 ---> 00:43:55,706 and then we're in week 1. 1048 00:43:55,706 ---> 00:43:56,966 So it turns out there is, in fact, 1049 00:43:56,966 ---> 00:44:00,626 a directory called 1 inside of lectures, inside of source, 1050 00:44:00,626 ---> 00:44:04,086 inside of pub, inside of CS-50's home directory and my goal is 1051 00:44:04,086 ---> 00:44:08,346 to copy it from there to here because I, now a student 1052 00:44:08,346 ---> 00:44:11,146 in the class, decide that I want to push ahead, I want to do this 1053 00:44:11,146 ---> 00:44:12,406 after class and play around. 1054 00:44:12,406 ---> 00:44:14,106 I want to copy David's source code 1055 00:44:14,106 ---> 00:44:16,176 into my own account just so I can play. 1056 00:44:16,176 ---> 00:44:20,516 Perfectly fine, notice that DOT represents this directory just 1057 00:44:20,516 ---> 00:44:22,946 as DOT DOT represents the parent directory. 1058 00:44:23,156 ---> 00:44:24,966 So if hit enter this is actually flawed, 1059 00:44:25,246 ---> 00:44:27,536 notice that something bad happened and then 1060 00:44:27,536 ---> 00:44:29,726 if I type LS I didn't get any files. 1061 00:44:29,966 ---> 00:44:33,286 So realize, too, sort of FAQ early on is if you want 1062 00:44:33,286 ---> 00:44:37,396 to copy a directory with CP you need to do it recursively, 1063 00:44:37,436 ---> 00:44:39,656 which is a keyword that we'll revisit in the term, 1064 00:44:39,656 ---> 00:44:41,596 it means to do it not only to that directory 1065 00:44:41,846 ---> 00:44:45,166 but all the files inside and all the subdirectories inside again 1066 00:44:45,166 ---> 00:44:46,856 and again and again until you bottom out. 1067 00:44:46,856 ---> 00:44:49,846 So CP-R means copy the file recursively 1068 00:44:50,146 ---> 00:44:52,836 into my current directory, enter, took a second 1069 00:44:52,836 ---> 00:44:54,256 because there are, in fact, a bunch of files. 1070 00:44:54,546 ---> 00:44:57,706 In fact if I go into my one directory now here are some 1071 00:44:57,706 ---> 00:45:00,056 examples that I've pre-prepared so that we can go off 1072 00:45:00,056 ---> 00:45:01,686 in a known direction here. 1073 00:45:01,926 ---> 00:45:06,976 So one direction we already went in was hi-1.c. but your version, 1074 00:45:06,976 ---> 00:45:08,826 on paper looks a little different from the quick 1075 00:45:08,826 ---> 00:45:10,566 and dirty thing I've been whipping up. 1076 00:45:10,676 ---> 00:45:14,086 there's a lot more purple on the screen here, so all the stuff 1077 00:45:14,086 ---> 00:45:17,796 at top is fundamentally irrelevant to the computer, 1078 00:45:17,916 ---> 00:45:20,606 but just like scratch does if you've discovered it yet, 1079 00:45:20,846 ---> 00:45:22,466 lets you put little comments here and there, 1080 00:45:22,466 ---> 00:45:24,376 sort of sticky notes, so to speak, post-it notes, 1081 00:45:24,646 ---> 00:45:26,936 so does C in most any high-level language. 1082 00:45:27,156 ---> 00:45:29,086 and by high-level language henceforth I mean something 1083 00:45:29,086 ---> 00:45:30,626 that's not 0s and 1s, 1084 00:45:30,626 ---> 00:45:32,066 not something called assembly language. 1085 00:45:32,386 ---> 00:45:33,846 It means ignore all 1086 00:45:33,846 ---> 00:45:36,246 of the following this is useful only to me the human. 1087 00:45:36,606 ---> 00:45:39,466 So in C the means by which you write a comment is 1088 00:45:39,496 ---> 00:45:43,926 to do a forward slash star and that means anything after that 1089 00:45:43,926 ---> 00:45:47,556 on this line or below will be ignored by the compiler, GCC, 1090 00:45:47,726 ---> 00:45:50,976 and the comment stops when you hit the opposite 1091 00:45:50,976 ---> 00:45:52,286 of that, star slash. 1092 00:45:52,916 ---> 00:45:56,196 So the fact that I actually have all of these stars and I've kind 1093 00:45:56,196 ---> 00:45:59,206 of boxed things in is really just some OCD on my part. 1094 00:45:59,206 ---> 00:46:02,036 It's not technical I just wanted to make a nice pretty purple box 1095 00:46:02,246 ---> 00:46:03,466 to box in all of my code. 1096 00:46:03,676 ---> 00:46:07,416 But one key takeaway is that I made sure that this line 1097 00:46:07,566 ---> 00:46:10,666 of stars and the slashes does not exceed the width 1098 00:46:10,666 ---> 00:46:11,346 of my window. 1099 00:46:11,566 ---> 00:46:13,866 So another lesson that's important early on is 1100 00:46:13,866 ---> 00:46:15,876 to make sure your -- the code you start writing is 1101 00:46:16,186 ---> 00:46:17,296 pretty printed. 1102 00:46:17,516 ---> 00:46:19,746 And this just means it actually displays nicely 1103 00:46:19,746 ---> 00:46:20,906 on a typical window. 1104 00:46:21,126 ---> 00:46:24,136 In real terms this means you should never at least 1105 00:46:24,186 ---> 00:46:27,546 for the C part of this course, have a line of text 1106 00:46:27,606 ---> 00:46:29,556 that is longer than 80 characters long. 1107 00:46:29,776 ---> 00:46:32,676 And even that's pushing it, 76 is kind of the geek's rule 1108 00:46:32,676 ---> 00:46:34,346 of thumb as to how long a line should be. 1109 00:46:34,646 ---> 00:46:37,316 How do you know what's 76 or what's 80 characters? 1110 00:46:37,486 ---> 00:46:41,446 Well, right now my window has essentially been expanded to be 1111 00:46:41,636 ---> 00:46:45,506 as long as I wanted it to be, but you get into the habit 1112 00:46:45,666 ---> 00:46:48,276 of knowing when to hit enter to move things onto the next line 1113 00:46:48,476 ---> 00:46:52,356 and nano and programs like it will actually force your lines 1114 00:46:52,356 ---> 00:46:54,276 to wrap if they start to get long. 1115 00:46:54,596 ---> 00:46:56,036 And this is just a matter of good style, 1116 00:46:56,066 ---> 00:46:58,956 because as you could imagine, if I wrote my whole program 1117 00:46:58,956 ---> 00:47:00,946 on just one line it would still work, 1118 00:47:00,946 ---> 00:47:04,546 the computer would not care, but you the humans probably would. 1119 00:47:04,546 ---> 00:47:07,426 In fact, this is hi1.c, let me go ahead 1120 00:47:07,426 ---> 00:47:09,036 and delete all that stuff. 1121 00:47:09,086 ---> 00:47:11,016 I'm going to go ahead and do this, you know, this, 1122 00:47:11,136 ---> 00:47:13,096 I really don't need that there. 1123 00:47:13,096 ---> 00:47:15,016 Let me go ahead and put that there. 1124 00:47:15,016 ---> 00:47:16,946 Right, if I'd given you a printout of this, I mean, 1125 00:47:16,946 ---> 00:47:20,666 rightly so would things start to look pretty damn complicated. 1126 00:47:20,666 ---> 00:47:22,216 Now some of these spaces are important 1127 00:47:22,216 ---> 00:47:23,646 so that you can distinguish what's ints 1128 00:47:23,646 ---> 00:47:26,206 and what's [inaudible], but if I go ahead and save this 1129 00:47:26,206 ---> 00:47:31,796 with control X, hit Y and now go ahead and run GCC of hi1.c, 1130 00:47:32,016 ---> 00:47:33,796 the program thankfully still compiles. 1131 00:47:33,796 ---> 00:47:36,636 I still have eight odd out, so it still works, this version, 1132 00:47:36,906 ---> 00:47:39,256 but it's certainly not very pretty printed 1133 00:47:39,256 ---> 00:47:40,396 and not very legible. 1134 00:47:40,396 ---> 00:47:42,016 So what else is inside of this file? 1135 00:47:42,256 ---> 00:47:44,676 Well, hmm, I didn't really want to do that. 1136 00:47:44,676 ---> 00:47:48,886 Let me go ahead and go back into CS-50, Pub source lectures 1, 1137 00:47:48,886 ---> 00:47:50,196 let me just get a new copy of this. 1138 00:47:50,546 ---> 00:47:53,856 So now it's going to prompt me, wait a minute, overwrite hi1.c, 1139 00:47:54,016 ---> 00:47:55,366 little sanity check, say yes. 1140 00:47:55,466 ---> 00:47:56,856 So now I have the prettier version back. 1141 00:47:56,856 ---> 00:47:59,776 I'm going to start using a program called VI or VIM just 1142 00:47:59,776 ---> 00:48:01,936 because frankly I'm more comfortable with it than nano, 1143 00:48:01,936 ---> 00:48:05,266 even though nano is simpler, do as I say not as I do. 1144 00:48:05,666 ---> 00:48:09,526 Hi1.c, still kind of pretty prints everything 1145 00:48:09,526 ---> 00:48:10,356 and color codes it. 1146 00:48:10,576 ---> 00:48:13,136 And the color is actually a feature that you don't get 1147 00:48:13,136 ---> 00:48:16,596 if you trying writing your first programs with notebad.exe 1148 00:48:16,846 ---> 00:48:19,236 or other similar client side programs. 1149 00:48:19,476 ---> 00:48:22,266 It's just making some inferences about the different roles 1150 00:48:22,266 ---> 00:48:23,646 that some of these keywords play, 1151 00:48:23,646 ---> 00:48:25,936 so I didn't write the word int in green. 1152 00:48:26,196 ---> 00:48:29,096 I didn't write the word char in green, it just knows 1153 00:48:29,136 ---> 00:48:31,076 that that represents the type of a variable. 1154 00:48:31,076 ---> 00:48:33,016 Let me draw David's attention to it 1155 00:48:33,056 ---> 00:48:34,656 with this default color scheme. 1156 00:48:34,986 ---> 00:48:36,316 So what's interesting here? 1157 00:48:36,396 ---> 00:48:38,916 Well, this stuff at the top is all comments, 1158 00:48:38,916 ---> 00:48:40,946 and actually now we get to use a fun little toy. 1159 00:48:40,946 ---> 00:48:43,106 this stuff up here is all comments. 1160 00:48:43,236 ---> 00:48:43,696 All right. 1161 00:48:43,696 ---> 00:48:45,846 So it's fundamentally irrelevant but useful 1162 00:48:45,846 ---> 00:48:47,196 for documenting your code. 1163 00:48:47,496 ---> 00:48:48,896 This things here I'm going 1164 00:48:48,896 ---> 00:48:52,016 to briefly call today a pre-processor directive, 1165 00:48:52,366 ---> 00:48:55,416 which is just a fancy way of saying tell the compiler 1166 00:48:55,616 ---> 00:48:57,586 to go get the contents of some other file 1167 00:48:57,706 ---> 00:48:59,246 that often someone else wrote. 1168 00:48:59,576 ---> 00:49:02,966 So what we don't have here is any kind 1169 00:49:02,966 ---> 00:49:05,186 of specification of what Print F does. 1170 00:49:05,246 ---> 00:49:06,646 Like who wrote Print F? 1171 00:49:06,746 ---> 00:49:10,096 I wrote this program called main, but who wrote Print F? 1172 00:49:10,096 ---> 00:49:11,716 Right, I'm kind of cutting corners here. 1173 00:49:11,986 ---> 00:49:15,566 Well, it turns out that when Linux shipped with the compiler, 1174 00:49:15,806 ---> 00:49:18,086 someone else, some really smart people spent a lot 1175 00:49:18,086 ---> 00:49:21,706 of time getting this very basic important function implemented 1176 00:49:21,706 ---> 00:49:23,206 in their own source code. 1177 00:49:23,446 ---> 00:49:29,156 So by saying sharp include open angle bracket standard io.h 1178 00:49:29,246 ---> 00:49:32,056 closed bracket, that's just telling GCC, you know what, 1179 00:49:32,186 ---> 00:49:34,876 the following code has some functions, some programs 1180 00:49:35,106 ---> 00:49:36,066 that other people wrote. 1181 00:49:36,296 ---> 00:49:37,976 Those programs happen to be inside 1182 00:49:37,976 ---> 00:49:41,666 of a file called standardio.h. please go grab the contents, 1183 00:49:41,926 ---> 00:49:44,676 paste them in here so that I don't have to do it myself. 1184 00:49:44,976 ---> 00:49:47,136 So I'm kind of oversimplifying there 1185 00:49:47,136 ---> 00:49:50,356 because in real terms what we're using here is a library. 1186 00:49:50,426 ---> 00:49:53,886 So a library of code henceforth is just a bunch of code 1187 00:49:53,886 ---> 00:49:56,976 that someone else wrote or maybe you wrote but that you factored 1188 00:49:56,976 ---> 00:49:59,336 out into separate files so that you don't have to copy 1189 00:49:59,336 ---> 00:50:01,426 and paste it into every future program you write. 1190 00:50:01,836 ---> 00:50:04,566 To technically my white lie I just told is 1191 00:50:04,566 ---> 00:50:06,926 that these program Print F these functions, 1192 00:50:06,926 ---> 00:50:09,706 actually as they should really be called, are not actually 1193 00:50:09,736 ---> 00:50:11,746 in that file, standardio.h, 1194 00:50:12,406 ---> 00:50:15,646 inside of that file will eventually see is just a minimal 1195 00:50:15,646 ---> 00:50:18,026 amount of information, essentially a summary of all 1196 00:50:18,026 ---> 00:50:20,636 of the functions in that file because as you might imagine, 1197 00:50:20,636 ---> 00:50:23,806 where is the actual implementation, the actual lines 1198 00:50:23,806 ---> 00:50:25,346 of code that implement Print F? 1199 00:50:25,386 ---> 00:50:28,726 What would the file name probably be called? 1200 00:50:29,496 ---> 00:50:33,336 Standardio.c, so in fact, yeah, there is a file out somewhere 1201 00:50:33,336 ---> 00:50:35,486 on the system called standardio.c 1202 00:50:35,486 ---> 00:50:38,206 that someone else implemented but there's a lot of lines 1203 00:50:38,206 ---> 00:50:40,256 of code in there, a normal human doesn't want to read through it 1204 00:50:40,256 ---> 00:50:43,016 so we have these header files which are called .h files 1205 00:50:43,266 ---> 00:50:45,446 and then c files which have actual code 1206 00:50:45,636 ---> 00:50:48,196 and initially I'm not making any header files myself, 1207 00:50:48,196 ---> 00:50:50,126 we'll get to that eventually but just realize, 1208 00:50:50,126 ---> 00:50:52,466 some of these minor tripping points early on are just 1209 00:50:52,466 ---> 00:50:54,826 about keeping programs relatively clean, so this, 1210 00:50:54,876 ---> 00:50:58,416 to be short, simply says, go get the contents of this file 1211 00:50:58,466 ---> 00:51:00,646 so that I can use functions like Print F 1212 00:51:01,216 ---> 00:51:02,476 and henceforth let me clarify. 1213 00:51:02,816 ---> 00:51:06,256 So I am writing a program, this program is arbitrarily going 1214 00:51:06,256 ---> 00:51:09,896 to be called hello, but I can override that as we've seen 1215 00:51:09,896 ---> 00:51:11,866 with the -o flag from GCC 1216 00:51:12,266 ---> 00:51:15,256 so programs are made up of functions. 1217 00:51:15,256 ---> 00:51:17,676 one or more functions and these are kind 1218 00:51:17,676 ---> 00:51:19,626 of like miniature programs just 1219 00:51:19,626 ---> 00:51:21,856 like your scratch projects are probably made 1220 00:51:21,856 ---> 00:51:23,316 up of multiple scripts. 1221 00:51:23,616 ---> 00:51:27,036 A script is a function so a function is just a piece of code 1222 00:51:27,036 ---> 00:51:29,456 that does something and as you can have multiple scripts 1223 00:51:29,456 ---> 00:51:32,506 in scratch you can have multiple functions in c and just 1224 00:51:32,506 ---> 00:51:35,866 as the default block or script and scratch is 1225 00:51:35,866 ---> 00:51:37,636 that thing called wingreenflag clicked, 1226 00:51:38,066 ---> 00:51:40,516 so in c is the default script, 1227 00:51:40,516 ---> 00:51:42,456 the default function called main. 1228 00:51:42,886 ---> 00:51:46,006 Now why, if its just called main do I need to write something 1229 00:51:46,006 ---> 00:51:49,906 like int and then ints and then RGC, char or this asterisks, 1230 00:51:49,906 ---> 00:51:52,836 this RGV this bracket notation, there's just a lot of crap 1231 00:51:52,836 ---> 00:51:55,156 at the beginning of a program when you're writing it in c, 1232 00:51:55,316 ---> 00:51:57,156 those of you who took app computer science know 1233 00:51:57,156 ---> 00:52:00,546 that there's classfoo public static, voidmain, its even worse 1234 00:52:00,596 ---> 00:52:02,406 in Java and frankly this is just 1235 00:52:02,406 ---> 00:52:06,456 because these languages were not designed with week 0 1236 00:52:06,456 ---> 00:52:07,916 of a programming class in mind. 1237 00:52:08,056 ---> 00:52:10,366 So again, its stupid stuff, you get past it quickly. 1238 00:52:10,546 ---> 00:52:13,006 For today we're going to wave our hands at details like that 1239 00:52:13,006 ---> 00:52:15,136 but to say for now it's a copy paste thing. 1240 00:52:15,136 ---> 00:52:18,166 To start writing a function you literally write int main 1241 00:52:18,166 ---> 00:52:20,926 and all the rest of that stuff but then the fun part 1242 00:52:20,926 ---> 00:52:23,996 or at least the intellectually interesting part happens 1243 00:52:23,996 ---> 00:52:25,536 in between the curly braces for now. 1244 00:52:25,996 ---> 00:52:28,406 So that's how I would go about printing this simple program. 1245 00:52:28,406 ---> 00:52:31,036 Let me actually take a look at a more interesting version, 1246 00:52:31,036 ---> 00:52:33,656 thought only slightly called high2.c 1247 00:52:33,656 ---> 00:52:35,586 and you have a printout of this. 1248 00:52:36,166 ---> 00:52:39,006 So what's the fundamental difference between version one 1249 00:52:39,116 ---> 00:52:41,356 and this one version two? 1250 00:52:41,956 ---> 00:52:44,926 Hopefully it jumps out at you. 1251 00:52:44,986 ---> 00:52:47,686 yeah, so if bit egotistically this jumps out at you 1252 00:52:47,686 ---> 00:52:50,656 that this program has my name immortalized in it, 1253 00:52:50,916 ---> 00:52:51,946 but how did I do this? 1254 00:52:51,946 ---> 00:52:53,816 Well it looks like I've got this additional line 1255 00:52:53,816 ---> 00:52:56,396 and so David is mentioned but what's going on? 1256 00:52:56,396 ---> 00:53:00,026 well even just using the jargon I started using earlier, string, 1257 00:53:00,246 ---> 00:53:01,586 because it comes before the name 1258 00:53:01,586 ---> 00:53:03,606 of a variable, means what precisely? 1259 00:53:03,606 ---> 00:53:06,706 Yeah, it's the type of variable. 1260 00:53:06,706 ---> 00:53:09,566 So the variable is called main, what's going to be inside 1261 00:53:09,566 ---> 00:53:11,626 of this variable, well its not going to be an int, 1262 00:53:11,626 ---> 00:53:14,346 because David is not an int, it's a string, it's a word, 1263 00:53:14,346 ---> 00:53:16,546 it's a sentence so I'm going to specify that the type 1264 00:53:16,546 ---> 00:53:18,046 of this variable is string, 1265 00:53:18,316 ---> 00:53:21,176 now the equal sign again is the assignment operator, 1266 00:53:21,176 ---> 00:53:23,446 it means put the value of the thing on the right 1267 00:53:23,596 ---> 00:53:26,096 on the inside the thing on the left so the value 1268 00:53:26,096 ---> 00:53:30,136 on the right is itself a string and in c as in many languages 1269 00:53:30,136 ---> 00:53:32,776 if you want to have a literal sequence 1270 00:53:32,776 ---> 00:53:34,586 of characters be treated as one unit, 1271 00:53:34,836 ---> 00:53:37,266 you put them in all double quotes. 1272 00:53:37,546 ---> 00:53:40,906 You can use single quotes but only around single characters, 1273 00:53:40,906 ---> 00:53:42,646 so those of you who know a little 1274 00:53:42,646 ---> 00:53:44,476 of html probably know it doesn't matter if you use single 1275 00:53:44,476 ---> 00:53:45,976 or double, it does matter. 1276 00:53:45,976 ---> 00:53:48,186 In many programming languages including c, 1277 00:53:48,396 ---> 00:53:50,176 so strings are double quotes. 1278 00:53:50,436 ---> 00:53:52,406 All right, then what do I do on the second line? 1279 00:53:52,646 ---> 00:53:54,766 Well, we've not quite seen this syntax 1280 00:53:55,466 ---> 00:53:58,366 but in laymen's term can someone explain what the percent s 1281 00:53:58,486 ---> 00:53:59,996 there represents? 1282 00:54:00,776 ---> 00:54:02,956 String. Right, really not that hard. 1283 00:54:02,956 ---> 00:54:06,716 Percent d happened to represent int, percent s represents string 1284 00:54:06,946 ---> 00:54:09,536 and so the thing after the comma means what do you want 1285 00:54:09,536 ---> 00:54:12,686 to substitute in for that formatting code, the percent s, 1286 00:54:13,176 ---> 00:54:14,506 put the name of the variable. 1287 00:54:14,556 ---> 00:54:20,206 All right, so more interesting, so GCC hi2.c enter, 1288 00:54:20,446 ---> 00:54:23,706 now I'm going to run a.out, ohi David 1289 00:54:23,786 ---> 00:54:26,906 but unfortunately its really not that interesting 1290 00:54:26,946 ---> 00:54:30,276 if your program is completely deterministic and always spits 1291 00:54:30,276 ---> 00:54:32,706 out the same result because really, I mean, 1292 00:54:32,706 ---> 00:54:35,066 there are so many easier ways to just say something like this 1293 00:54:35,066 ---> 00:54:38,366 than this set up so let's take a look at the third version 1294 00:54:38,366 ---> 00:54:40,246 of this which is a little more interesting 1295 00:54:40,246 ---> 00:54:42,746 and finally we get a compelling use for a keyboard, 1296 00:54:43,046 ---> 00:54:46,056 so this program differs for the comments up top 1297 00:54:46,206 ---> 00:54:48,296 in that there's a third line of code here 1298 00:54:48,586 ---> 00:54:51,396 that uses a new function, so we've been using Print F 1299 00:54:51,546 ---> 00:54:53,856 to send output, it turns out that you can also, 1300 00:54:54,176 ---> 00:54:56,056 nicely enough, get input from the user. 1301 00:54:56,296 ---> 00:54:58,896 So not by way of the mouse, at least in this context but by way 1302 00:54:58,896 ---> 00:55:00,906 of the keyboard and what's the new function, 1303 00:55:01,246 ---> 00:55:04,216 just to take an obvious guess here, get string. 1304 00:55:04,576 ---> 00:55:07,696 As the name implies, the function get strings purpose 1305 00:55:07,696 ---> 00:55:10,586 in life is to get a string from the user and do what 1306 00:55:10,586 ---> 00:55:12,856 with the result apparently? 1307 00:55:13,026 ---> 00:55:16,256 Store it. so functions we now see right away, 1308 00:55:16,256 ---> 00:55:19,536 have this ability not only to do something aesthetically, 1309 00:55:19,586 ---> 00:55:23,246 Print F has this so called side effect of displaying something 1310 00:55:23,246 ---> 00:55:26,516 on the screen but functions can also return a value 1311 00:55:26,516 ---> 00:55:29,236 so you can think of a function kind of as a black box 1312 00:55:29,456 ---> 00:55:32,316 that does some work and then can maybe hand you some answers 1313 00:55:32,496 ---> 00:55:33,926 and its up to you, the programmer, 1314 00:55:33,926 ---> 00:55:36,006 to decide if you're going to do anything with that answer. 1315 00:55:36,226 ---> 00:55:37,446 How do you do something with it? 1316 00:55:37,446 ---> 00:55:39,976 well one of the things you could do is keep the answer around. 1317 00:55:40,556 ---> 00:55:42,886 So by having string name on the left 1318 00:55:42,886 ---> 00:55:45,596 that says give me a variable called name, it's a type sting, 1319 00:55:45,596 ---> 00:55:47,586 what are you going to put inside of it? 1320 00:55:47,746 ---> 00:55:49,396 well, whatever the result is. 1321 00:55:49,476 ---> 00:55:52,066 The return value so to speak of the thing on the right 1322 00:55:52,166 ---> 00:55:54,246 so get string returns now a value. 1323 00:55:54,546 ---> 00:55:56,336 How does this all behave in reality? 1324 00:55:56,336 ---> 00:56:00,086 So GCC hi3.c, I'm getting a little tired of a.out, 1325 00:56:00,086 ---> 00:56:01,286 how do I give this a better name? 1326 00:56:02,656 ---> 00:56:07,276 yes, so -o for output, and then let's call it hi3 though I could 1327 00:56:07,276 ---> 00:56:13,726 call it anything I want, oh, oh, did I create a problem there? 1328 00:56:13,846 ---> 00:56:20,286 its kind of a coincidence, so still the same error, yeah, 1329 00:56:20,286 ---> 00:56:24,006 so correct, fancy correct answer so there's a problem here 1330 00:56:24,136 ---> 00:56:25,976 in that get string is a function, 1331 00:56:25,976 ---> 00:56:28,526 yes but it wasn't written by the original authors 1332 00:56:28,526 ---> 00:56:31,976 of the c programming language, in fact just getting input 1333 00:56:31,976 ---> 00:56:34,146 from the user in c is really a pain. 1334 00:56:34,146 ---> 00:56:36,596 You have to use a function among others called scanf 1335 00:56:36,596 ---> 00:56:39,006 and we'll use this eventually, there's other tricks too, 1336 00:56:39,126 ---> 00:56:41,196 but long story short, in week one of a course, 1337 00:56:41,196 ---> 00:56:44,566 especially this course, to complete a bunch of hurdles, 1338 00:56:44,566 ---> 00:56:47,076 you have to jump through as simple as get a character 1339 00:56:47,076 ---> 00:56:49,006 from the keyboard, even in Java, those of you familiar 1340 00:56:49,006 ---> 00:56:51,046 with the scanner class, even that is a pain 1341 00:56:51,046 ---> 00:56:53,766 to actually use I'd say in the first week of a class 1342 00:56:54,256 ---> 00:56:56,096 so notice what did I do in this file? 1343 00:56:56,316 ---> 00:56:58,946 I did one other thing besides mention get string. 1344 00:56:59,226 ---> 00:57:01,696 There's one other key difference outside of the comments. 1345 00:57:02,096 ---> 00:57:03,116 What else is new here? 1346 00:57:05,386 ---> 00:57:08,246 yeah, so I'm not just using the standard io library, 1347 00:57:08,276 ---> 00:57:12,086 it turns out that the cs50 staff a few years ago wrote our 1348 00:57:12,086 ---> 00:57:13,296 own library. 1349 00:57:13,466 ---> 00:57:15,486 And we wrote what that means, two files. 1350 00:57:15,486 ---> 00:57:18,526 One called cs50.h and one called cs50.c 1351 00:57:18,726 ---> 00:57:20,506 and in the latter we wrote a bunch of functions 1352 00:57:20,506 ---> 00:57:22,156 that we thought would be useful to students 1353 00:57:22,156 ---> 00:57:26,746 in the semester namely get int and get string and silly name, 1354 00:57:26,746 ---> 00:57:29,296 but get long long but other functions still 1355 00:57:29,476 ---> 00:57:32,236 that really simplify the process at least at the start 1356 00:57:32,236 ---> 00:57:34,556 of the semester of getting keyboard input from users 1357 00:57:34,826 ---> 00:57:37,826 but unfortunately its not sufficient just to tell GCC, 1358 00:57:37,886 ---> 00:57:41,466 hey make sure you go get a copy of the header file 1359 00:57:41,466 ---> 00:57:43,936 for cs50's library so I know that these functions exist, 1360 00:57:43,936 ---> 00:57:44,906 because I've done that. 1361 00:57:44,906 ---> 00:57:48,736 So one mistake might have been to omit this line together, 1362 00:57:48,736 ---> 00:57:49,636 that would in fact be bad. 1363 00:57:50,256 ---> 00:57:51,836 But that's not the only mistake that I made, 1364 00:57:51,836 ---> 00:57:54,116 I now need to tell cs50's library 1365 00:57:54,416 ---> 00:57:57,516 when you compile this you don't just get away 1366 00:57:57,516 ---> 00:58:01,676 with turning one file, hi3.c into 0's and 1's 1367 00:58:01,896 ---> 00:58:05,106 because you need access to one other file, called what? 1368 00:58:05,566 ---> 00:58:08,626 Yes, so cs50.c so there's a couple solutions here, 1369 00:58:08,626 ---> 00:58:10,436 I could email the core staff, and I could say, 1370 00:58:10,436 ---> 00:58:14,126 hey could I have a copy of cs50.c or they'll be happy 1371 00:58:14,126 ---> 00:58:16,066 to give it because there's no intellectual property there, 1372 00:58:16,066 ---> 00:58:19,276 its just standard c stuff, but that seems kind of wasteful 1373 00:58:19,276 ---> 00:58:21,326 if every time in the semester if you write a program you need 1374 00:58:21,326 ---> 00:58:23,556 to copy the R file, put it in your own directory, 1375 00:58:23,556 ---> 00:58:24,706 kind of bloat your own code, 1376 00:58:24,956 ---> 00:58:26,446 well in fact there's an easier way. 1377 00:58:26,446 ---> 00:58:31,756 You can tell GCC to link against our library 1378 00:58:31,756 ---> 00:58:33,406 and long story short is what this mean, 1379 00:58:33,406 ---> 00:58:37,106 is when GCC is converting hi3.c from source code 1380 00:58:37,106 ---> 00:58:39,646 into object code, from human readable to 0's 1381 00:58:39,676 ---> 00:58:43,486 and 1's it means, oh by the way, go get the library, -l, 1382 00:58:43,746 ---> 00:58:47,546 called cs50 and merge the two at the very last minute 1383 00:58:47,586 ---> 00:58:51,886 so that the file you get out hi3 or a.out contains 0's and 1's 1384 00:58:51,886 ---> 00:58:53,256 from both of those files. 1385 00:58:53,506 ---> 00:58:56,556 So again, another silly detail that's very easy to forget 1386 00:58:56,796 ---> 00:58:58,626 but just to kind of drill it into your minds 1387 00:58:58,626 ---> 00:59:00,276 if you ever see this semester, 1388 00:59:00,496 ---> 00:59:02,566 a message about undefined references, 1389 00:59:03,046 ---> 00:59:05,276 probably means you forgot something simple 1390 00:59:05,276 ---> 00:59:08,126 like that library that you wanted to use, -lcs50. 1391 00:59:08,186 ---> 00:59:11,216 there's others, -lm gives you a math library. 1392 00:59:11,216 ---> 00:59:14,536 There's -lcrypt which gives you a cryptography library and stuff 1393 00:59:14,536 ---> 00:59:16,236 like that, but it did work this time. 1394 00:59:16,236 ---> 00:59:19,776 when I said go ahead and link in this file, I did in fact get hi3 1395 00:59:19,886 ---> 00:59:25,616 so if I run hi3 state your name, we'll say Jensue, 1396 00:59:25,886 ---> 00:59:28,096 well hi Jensue, well what about Yuki? 1397 00:59:28,936 ---> 00:59:31,926 Okay so now I have, still kind of overwhelming right? 1398 00:59:31,926 ---> 00:59:33,556 not anything to write home about 1399 00:59:33,746 ---> 00:59:36,026 but at least it's a dynamic program that's starting 1400 00:59:36,026 ---> 00:59:39,096 to do a little bit more so just to give you a sense now 1401 00:59:39,096 ---> 00:59:42,626 of some formalities, one I've used here, Print F, 1402 00:59:42,706 ---> 00:59:45,646 a couple of times, I've used it pretty simply to use things 1403 00:59:45,646 ---> 00:59:48,936 like strings and ints but we can do more powerful things with it 1404 00:59:48,936 ---> 00:59:51,946 and in fact you'll have to get used to sort of a new sort 1405 00:59:51,946 ---> 00:59:54,266 of a world where people write things somewhat cryptically 1406 00:59:54,266 ---> 00:59:57,046 sometimes, this is an excerpt from the man page, 1407 00:59:57,046 ---> 00:59:59,556 the manual page for Print F and the way you, 1408 00:59:59,556 ---> 01:00:00,646 the programmer know, how 1409 01:00:00,646 ---> 01:00:03,466 to use a function is often frankly, by rtfm. 1410 01:00:03,746 ---> 01:00:04,946 Just read the manual. 1411 01:00:05,266 ---> 01:00:07,346 And actually look up what the instructions are, 1412 01:00:07,436 ---> 01:00:08,486 Google it later if you'd like. 1413 01:00:08,836 ---> 01:00:11,766 For those less comfortable and less familiar with the speak. 1414 01:00:12,576 ---> 01:00:13,736 So what you'll find 1415 01:00:13,736 ---> 01:00:15,806 on the courses website throughout the semester 1416 01:00:15,806 ---> 01:00:17,356 under resources we have a bunch 1417 01:00:17,356 ---> 01:00:19,676 of links we think you'll find useful and one 1418 01:00:19,676 ---> 01:00:22,716 of them is this wonderful site called cppreference.com. 1419 01:00:22,716 ---> 01:00:25,506 the only downside of it means cpp means c plus plus 1420 01:00:25,886 ---> 01:00:28,676 so the author of the site actually made it fairly c plus 1421 01:00:28,756 ---> 01:00:31,036 plus specific so under resources 1422 01:00:31,036 ---> 01:00:34,276 on the courses web sit we have our own copy of this website 1423 01:00:34,276 ---> 01:00:37,036 because he open sourced it to everyone so if I actually go 1424 01:00:37,036 ---> 01:00:42,456 to cs50.net/resources what you'll see up here 1425 01:00:42,456 ---> 01:00:44,686 under the link to c is a bunch of things, 1426 01:00:44,686 ---> 01:00:50,226 most of which we won't need just yet, but if I go to reference, 1427 01:00:50,606 ---> 01:00:53,686 this is a wonderful useful sight and this is one of the reasons 1428 01:00:53,686 ---> 01:00:55,856 that you don't really need a book for a course like this 1429 01:00:56,076 ---> 01:00:58,566 because so much good stuff is available on line. 1430 01:00:58,876 ---> 01:01:01,006 If I know that I'm doing something with io, 1431 01:01:01,006 ---> 01:01:04,336 that sounds cryptic, but it just means input output print get 1432 01:01:04,496 ---> 01:01:06,696 stuff like that, notice if I scroll down here, 1433 01:01:06,926 ---> 01:01:08,966 clearly we're only scratching the surface today 1434 01:01:08,966 ---> 01:01:10,836 of what C can do and I was interested 1435 01:01:10,836 ---> 01:01:12,236 in what Print F can do 1436 01:01:12,486 ---> 01:01:14,906 and here's just fairly user friendly documentation 1437 01:01:14,906 ---> 01:01:18,746 of the other codes you can use so we saw already, let's see, 1438 01:01:18,746 ---> 01:01:21,586 percent d and there it is at the top for signed integers, 1439 01:01:21,686 ---> 01:01:23,826 things that may or may not have negative sign in front, 1440 01:01:24,026 ---> 01:01:25,796 percents for a string of characters 1441 01:01:26,016 ---> 01:01:27,886 but there's some other stuff here too that we may 1442 01:01:27,886 ---> 01:01:30,086 or may not use in this semester, but what's nice 1443 01:01:30,086 ---> 01:01:32,126 about this site is it give you sample code, 1444 01:01:32,306 ---> 01:01:35,416 it tells you what library, what header file you must include 1445 01:01:35,416 ---> 01:01:36,606 at the top of your program 1446 01:01:36,866 ---> 01:01:39,356 and then it tells you what the functions signature is, 1447 01:01:39,586 ---> 01:01:41,626 what is sort of the canonical form of this thing 1448 01:01:41,626 ---> 01:01:44,036 so you can begin to understand how you use it 1449 01:01:44,036 ---> 01:01:46,296 and again you'll get much more acclimated to this 1450 01:01:46,626 ---> 01:01:47,866 over the course of the semester 1451 01:01:47,866 ---> 01:01:50,266 but we can do more interesting things with this. 1452 01:01:50,556 ---> 01:01:53,496 So just as there's n for new line, 1453 01:01:53,796 ---> 01:01:57,216 there's r for carriage return, so if you think back 1454 01:01:57,216 ---> 01:01:59,676 to retro typewriters when you hit enter 1455 01:01:59,676 ---> 01:02:01,056 on an old fashioned typewriter, 1456 01:02:01,286 ---> 01:02:03,236 not only did the paper move this way, 1457 01:02:03,236 ---> 01:02:06,616 the little typing head moved this way 1458 01:02:06,856 ---> 01:02:08,906 so a carriage return moves the curser all the curser all the 1459 01:02:08,906 ---> 01:02:11,656 way back to the left, a new line moves it down one line 1460 01:02:12,086 ---> 01:02:14,526 so this is another sort of stupid thing 1461 01:02:14,526 ---> 01:02:17,836 from religious battles past so in the Windows world, 1462 01:02:17,836 ---> 01:02:21,196 most text files end with what's called a carriage return 1463 01:02:21,356 ---> 01:02:22,836 and a line feed. 1464 01:02:22,836 ---> 01:02:25,346 Crlf, which means rn. 1465 01:02:26,326 ---> 01:02:29,036 in the Linux world people were much more conservative, 1466 01:02:29,036 ---> 01:02:33,756 they just used new lines and n in many systems, Macs and, 1467 01:02:34,486 ---> 01:02:36,266 actually not so much Mac sometimes, 1468 01:02:36,266 ---> 01:02:39,546 so in Linux computers n means yes go to the next line 1469 01:02:39,756 ---> 01:02:42,556 and go all the way to the left so I'm just kind of grimacing 1470 01:02:42,556 ---> 01:02:44,426 at some of these details because these things too, 1471 01:02:44,646 ---> 01:02:46,206 are little things you trip over early on. 1472 01:02:46,206 ---> 01:02:48,136 they're fundamentally not that interesting but you get used 1473 01:02:48,136 ---> 01:02:50,006 to little trivia or minutia like this. 1474 01:02:50,276 ---> 01:02:53,936 But this does beg the question, if n means new line, 1475 01:02:54,326 ---> 01:02:56,866 r means carriage return, 1476 01:02:57,166 ---> 01:03:01,306 how do you just write a literal ? Well the answer is there 1477 01:03:01,306 ---> 01:03:03,806 but this is a common pattern, what is it? 1478 01:03:04,776 ---> 01:03:07,396  so unfortunately a little weird, you kind of have 1479 01:03:07,446 ---> 01:03:09,476 to have a corner case like that if you want a literal 1480 01:03:09,686 ---> 01:03:12,536 and a string you escape the but this notion 1481 01:03:12,536 ---> 01:03:14,686 of escaping is something we'll see quite a bit. 1482 01:03:15,036 ---> 01:03:16,356 Well, it turns out we can do stuff 1483 01:03:16,416 ---> 01:03:19,776 with not just ints not just strings, there are chars 1484 01:03:19,776 ---> 01:03:21,026 for individual characters, 1485 01:03:21,026 ---> 01:03:23,616 doubles for floating point values and float 1486 01:03:23,616 ---> 01:03:25,026 for floating point values and all 1487 01:03:25,026 ---> 01:03:27,556 of these have some different meaning, in fact let me go ahead 1488 01:03:27,846 ---> 01:03:29,986 to an example that's not just text space now, 1489 01:03:30,226 ---> 01:03:32,406 but just to demonstrate, again, to underwhelm, 1490 01:03:32,406 ---> 01:03:33,636 at first because we can definitely one 1491 01:03:33,636 ---> 01:03:37,036 up ourselves easily that math is not hard and c. 1492 01:03:37,346 ---> 01:03:40,066 so here's a program that assigns a variable called x, 1493 01:03:40,426 ---> 01:03:44,486 I'll type integer the value of 1; 1494 01:03:44,556 ---> 01:03:48,696 variable called y type is int, assign it a value of 2 right, 1495 01:03:48,696 ---> 01:03:50,256 new syntax, not interesting. 1496 01:03:50,346 ---> 01:03:53,476 Finally I declare a third variable called z its also going 1497 01:03:53,476 ---> 01:03:56,516 to store an int, its going to store the sum of x and y, 1498 01:03:57,186 ---> 01:04:01,406 looks pretty good but let me go ahead and let me run GCC 1499 01:04:01,576 ---> 01:04:03,896 of math1.c okay, interesting. 1500 01:04:04,186 ---> 01:04:07,036 So it turns out GCC, especially the way we have it configured 1501 01:04:07,036 ---> 01:04:11,826 on nice.faf can also be a bit anal and a little cautious 1502 01:04:11,826 ---> 01:04:13,466 on your behalf saying you know what, 1503 01:04:13,896 ---> 01:04:15,186 odds are you screwed up here. 1504 01:04:15,296 ---> 01:04:16,526 right? its saying it very nicely, 1505 01:04:16,576 ---> 01:04:19,106 warning unused variable z but that's telling you 1506 01:04:19,106 ---> 01:04:21,236 that you did something, you're not using it, 1507 01:04:21,486 ---> 01:04:23,756 probably wasn't a very productive program you just 1508 01:04:23,756 ---> 01:04:24,896 wrote, but let's try it. 1509 01:04:24,936 ---> 01:04:28,866 let's be stubborn and let's run a.out enter, hmm. 1510 01:04:29,316 ---> 01:04:32,876 Is it not working? 1511 01:04:34,226 ---> 01:04:35,886 Its actually working perfectly. 1512 01:04:37,456 ---> 01:04:40,256 Right, the math is correct, what is in z 1513 01:04:40,256 ---> 01:04:41,496 at this point, oh, missed it. 1514 01:04:41,656 ---> 01:04:44,146 the problem is what? 1515 01:04:44,146 ---> 01:04:44,746 Simple answer. 1516 01:04:46,796 ---> 01:04:49,736 I'm not doing anything with it, yes I created 3 variables, 1517 01:04:49,736 ---> 01:04:52,406 all of them at some point in time, do in fact have numbers 1518 01:04:52,406 ---> 01:04:55,036 like 1 2 and hopefully 3 inside of them 1519 01:04:55,236 ---> 01:04:56,896 but if you don't do anything with it, 1520 01:04:57,166 ---> 01:04:58,986 sort of the tree falling in the woods right? 1521 01:04:58,986 ---> 01:05:01,876 no one knows that the answer you just computed was three unless 1522 01:05:01,876 ---> 01:05:05,046 you print it, save it, do something with it, 1523 01:05:05,266 ---> 01:05:07,096 so hopefully there's a solution here. 1524 01:05:07,096 ---> 01:05:09,386 so let's take a look at the second, slightly fixed version 1525 01:05:09,386 ---> 01:05:11,246 of this, so how do I print out the result? 1526 01:05:11,246 ---> 01:05:13,316 Well again, let's just go into our little tool kit that's going 1527 01:05:13,316 ---> 01:05:15,006 to start being filled with more function still, 1528 01:05:15,286 ---> 01:05:18,086 Print F quote unquotes the quotes are important, 1529 01:05:18,266 ---> 01:05:21,416 the percent means display this as an integer and then I pass 1530 01:05:21,416 ---> 01:05:24,556 in z and so, okay, so now not only have I written a correct 1531 01:05:24,556 ---> 01:05:28,456 program, I'm actually doing something productive with it, 1532 01:05:28,516 ---> 01:05:32,876 a.out, now gives -- hmm, still a little weird, its not incorrect 1533 01:05:32,876 ---> 01:05:34,906 but what's that explanation for this weirdness. 1534 01:05:36,366 ---> 01:05:38,696 Right, so there's just no new line, so let me go in here 1535 01:05:38,946 ---> 01:05:42,056 and I'm going to move over here, add between the quotes 1536 01:05:42,056 ---> 01:05:45,686 but after the percentn let me recompile, 1537 01:05:45,686 ---> 01:05:47,706 another little Linux trick, if you get tired 1538 01:05:47,706 ---> 01:05:49,516 of typing the same commands over and over again, 1539 01:05:49,786 ---> 01:05:52,006 you can either hit up and that will scroll 1540 01:05:52,036 ---> 01:05:53,846 through the commands you previously typed 1541 01:05:53,976 ---> 01:05:55,576 or you can hit ! 1542 01:05:55,746 ---> 01:05:59,746 aka bang and type the first letter or so of the last command 1543 01:05:59,746 ---> 01:06:01,696 that starts with that sequence and hit enter 1544 01:06:01,696 ---> 01:06:04,016 and if I haven't forgotten some other g command I wrote, 1545 01:06:04,306 ---> 01:06:07,086 it should remember, aha, it was gccmath2.c, 1546 01:06:07,086 ---> 01:06:09,136 again little things you pick up over time. 1547 01:06:09,806 ---> 01:06:11,706 and if I run a.out, 1548 01:06:11,706 ---> 01:06:14,106 okay slightly prettier, slightly prettier. 1549 01:06:14,326 ---> 01:06:16,946 So what else can we do here, well there's going 1550 01:06:16,946 ---> 01:06:20,436 to be other data types still but there's also this format strings 1551 01:06:20,436 ---> 01:06:23,206 so let's see if we can't do a little bit 1552 01:06:23,206 ---> 01:06:25,356 of something that's more interesting underneath the hood 1553 01:06:25,356 ---> 01:06:27,736 so it turns out we have format strings, 1554 01:06:28,006 ---> 01:06:29,586 but there's also this approach here, 1555 01:06:29,586 ---> 01:06:30,736 let me go back to the code. 1556 01:06:30,736 ---> 01:06:32,666 This is a program, again, that you have a print out of, 1557 01:06:33,016 ---> 01:06:36,046 called size of, and here's where we finally scratch the surface 1558 01:06:36,046 ---> 01:06:37,786 of actual design issues. 1559 01:06:38,186 ---> 01:06:40,586 Actual questions that you are interested to answer 1560 01:06:40,736 ---> 01:06:43,436 because they really will affect the correctness of your program 1561 01:06:43,436 ---> 01:06:44,726 and what you can do with it. 1562 01:06:44,986 ---> 01:06:47,516 so this program, its not very long, its about half comments 1563 01:06:47,516 ---> 01:06:48,546 and half actual code, 1564 01:06:48,806 ---> 01:06:51,306 notice that at the top here I've declared some variables 1565 01:06:51,306 ---> 01:06:53,656 in advance, so this is kind of interesting. 1566 01:06:54,036 ---> 01:06:56,486 Even though thus far I've very efficiently, 1567 01:06:56,486 ---> 01:06:58,706 very analy been declaring a variable on the left 1568 01:06:58,706 ---> 01:07:01,436 and then doing something with it on the right, all in one line, 1569 01:07:01,836 ---> 01:07:02,916 you don't need to do that. 1570 01:07:02,916 ---> 01:07:04,686 If you know you're going to need a variable, 1571 01:07:04,886 ---> 01:07:07,946 you can declare the variable earlier in your program 1572 01:07:07,996 ---> 01:07:11,286 and then use it later and you'll learn over time when this is 1573 01:07:11,286 ---> 01:07:14,486 and isn't appropriate, but here I've declared three types 1574 01:07:14,486 ---> 01:07:15,046 of values. 1575 01:07:15,046 ---> 01:07:17,466 A char, a double, a float and an int. 1576 01:07:17,976 ---> 01:07:20,356 a float is a floating point value a real number, 1577 01:07:20,356 ---> 01:07:24,276 something with a decimal point, what's a double perhaps? 1578 01:07:25,156 ---> 01:07:26,086 Any ideas? 1579 01:07:27,156 ---> 01:07:28,496 So its twice something, 1580 01:07:28,726 ---> 01:07:31,786 its actually a floating point value that's twice 1581 01:07:31,786 ---> 01:07:32,916 as big potentially. 1582 01:07:33,176 ---> 01:07:35,916 So it turns out that in this language and in some others, 1583 01:07:36,126 ---> 01:07:37,766 there are actually pre defined meanings 1584 01:07:37,766 ---> 01:07:40,486 for how many bits are used to represent a data type, 1585 01:07:40,796 ---> 01:07:44,816 so we have chars or 8 bits on a typical modern computer 1586 01:07:44,856 ---> 01:07:48,396 with intel inside, a double is, and let's come back to that. 1587 01:07:48,396 ---> 01:07:52,036 A float is 32 bits, now that's pretty big, 1588 01:07:52,036 ---> 01:07:55,396 because if an int is also 32 bits, what did we say last week, 1589 01:07:55,396 ---> 01:07:56,646 the biggest number you can represent 1590 01:07:56,646 ---> 01:07:59,726 with 32 bits is, like 4 billion. 1591 01:07:59,726 ---> 01:08:01,866 Now wait a minute, if you're omitting negative numbers 1592 01:08:01,866 ---> 01:08:03,606 so if its negative numbers also then its 1593 01:08:03,606 ---> 01:08:06,746 like negative two billion, to positive 2 billion roughly 1594 01:08:06,746 ---> 01:08:08,056 but a total of 4 billion 1595 01:08:08,336 ---> 01:08:12,106 so floating point values also use 32 bits but they use them 1596 01:08:12,106 ---> 01:08:15,286 to have some numbers before the decimal point, 1597 01:08:15,596 ---> 01:08:18,006 some after so you can't, it's a trade off 1598 01:08:18,006 ---> 01:08:19,686 between how big a number you can represent 1599 01:08:19,686 ---> 01:08:23,066 as a floating point value versus how many points you can have 1600 01:08:23,066 ---> 01:08:26,476 after the decimal point but a double now is not 32 bits, 1601 01:08:26,566 ---> 01:08:29,246 right, I'm kind of beyond the scope of my arms here, 1602 01:08:29,496 ---> 01:08:31,656 its 64 bits and that's pretty damn big 1603 01:08:31,826 ---> 01:08:34,296 so you'll have some discretion there so what does it mean 1604 01:08:34,296 ---> 01:08:38,746 when I run this down here, Print F all right, so print an int 1605 01:08:38,746 ---> 01:08:40,226 and a new line, but what do you want to print? 1606 01:08:40,556 ---> 01:08:43,286 Well there's this operator in c, that's only occasionally useful, 1607 01:08:43,356 ---> 01:08:46,596 today its marginally enlightening, tell me the size 1608 01:08:46,596 ---> 01:08:50,046 of the variable c. tell me the size of the variable d, f, 1609 01:08:50,046 ---> 01:08:53,886 and i so let me go ahead and run a GCC on sizeof.c now I'm going 1610 01:08:54,136 ---> 01:08:58,176 to go ahead and run a.out, wait a minute, those are not 1611 01:08:58,176 ---> 01:09:00,366 in fact values like 32 and 64. 1612 01:09:00,366 ---> 01:09:01,296 what am I seeing? 1613 01:09:02,816 ---> 01:09:03,746 Yeah, I'm seeing bytes. 1614 01:09:03,936 ---> 01:09:06,196 That's kind of interesting, okay, so that's fine, 1615 01:09:06,446 ---> 01:09:07,736 let me take a look at one other thing. 1616 01:09:07,736 ---> 01:09:10,686 I saw on the screen a moment ago that there's this mention 1617 01:09:10,686 ---> 01:09:15,106 of longs so let me say long is an l and let me print 1618 01:09:15,106 ---> 01:09:20,586 out its length here, so long and I think its l, hopefully, %, 1619 01:09:21,336 ---> 01:09:28,166 let's see, GCC sizeofc, oops not l, dammit, what is it? 1620 01:09:28,806 ---> 01:09:29,716 is it also d? 1621 01:09:30,796 ---> 01:09:31,586 yes all right. 1622 01:09:31,916 ---> 01:09:35,576 if I run this now what do you think a long is going to be? 1623 01:09:35,576 ---> 01:09:42,246 So int was 4, also 4, so again, sort of a historical artifact, 1624 01:09:42,386 ---> 01:09:44,206 when I mentioned long longs before, 1625 01:09:44,536 ---> 01:09:46,796 so if you want an int that's bigger than 32 bits, 1626 01:09:46,796 ---> 01:09:49,446 you want a 64 bit int, its not a long, because a long is the same 1627 01:09:49,446 ---> 01:09:51,646 as an int, it's a long long that you want. 1628 01:09:51,646 ---> 01:09:54,536 So again, sort of random c trivia. 1629 01:09:54,886 ---> 01:09:55,796 But I thought we'd end with this. 1630 01:09:56,206 ---> 01:09:59,256 Here's a crazy looking program, I loaded this off the internet, 1631 01:09:59,546 ---> 01:10:02,196 written by a really, either a really brilliant person 1632 01:10:02,196 ---> 01:10:04,486 or a person with really a lot of free time. 1633 01:10:04,836 ---> 01:10:07,836 so this is an obfuscated C program 1634 01:10:08,156 ---> 01:10:10,756 and you are entering a community that you don't have to stay 1635 01:10:10,756 ---> 01:10:14,246 in in perpetuity of people who like writing programs like this, 1636 01:10:14,246 ---> 01:10:16,196 or have the ability to do it and there are contests 1637 01:10:16,336 ---> 01:10:20,146 that people run for obfuscated c contests whereby you challenge 1638 01:10:20,216 ---> 01:10:23,176 people to write the most confusing looking program you 1639 01:10:23,176 ---> 01:10:25,876 could possibly come up with that no human should be able 1640 01:10:25,876 ---> 01:10:28,076 to understand and then you challenge the audience, 1641 01:10:28,116 ---> 01:10:31,116 the other geeks in the room, what that program actually does, 1642 01:10:31,686 ---> 01:10:34,816 do you have any idea what this is going to do? 1643 01:10:34,816 ---> 01:10:37,006 We will not be writing things like this. 1644 01:10:37,216 ---> 01:10:39,606 This is an exercise in the opposite of good design, 1645 01:10:39,886 ---> 01:10:41,986 but its kind of a powerful thing, 1646 01:10:42,196 ---> 01:10:44,146 that if we run the compiler here, the warnings I'm going 1647 01:10:44,146 ---> 01:10:45,276 to ignore for now, that's fine. 1648 01:10:45,566 ---> 01:10:47,026 A.out, I'll give you the results 1649 01:10:47,026 ---> 01:10:50,236 of your first obfuscated c program which is, 1650 01:10:51,546 ---> 01:10:52,866 that's what that does. 1651 01:10:53,036 ---> 01:10:53,796 We'll see you on Friday.