The other person receives a text message with a code to take to the local M-Pesa agent to get the money.
VOA: special.2009.11.02
So I'm going to comment those out, and let's go down to this piece of code, and uncomment it.
那么我会把这些注释上,让我们看看这段代码,取消注释。
I'm going to start somewhere near the middle of the code. Again, a lot of times, people don't do that.
我会在代码中间的某个位置开始,再说一次,很多时候人们不会这么做。
So, I'm getting a string and so what really am I doing in this line of code?
那么,我得到一个字符串,这行代码实际上是干什么的呢?
Because I might have written some code in which I'm expecting that integer particular variable to have an integer value.
因为我可能写了一些代码,来把一些,变量的类型,指定为。
We want to write a piece of code that helps these guys out, so I'm going to show you an example.
通过写一段代码,来解决一个这样的问题,接下来让我们来看个例子。
Let's assume, for sake of argument, the thing I'm looking for is bigger than this. In that case, I'm going to throw away all of this, I'm going to hit that bottom line of that code.
让我们假定不是,假定要找的元素,比这个大,在这样的情况下,这些都擦掉,我要运行到代码的最后一行。
Code is right here. And all it's doing is when I'm getting into the different places I'm simply printing out information about where I am. What I want you to see palindrome is notice what happened here.
代码就在这儿,它的作用是当我运行到不同地方时,就输出我所在方位的信息,我想让你们看的就是注意这儿发生了什么,好了我调用了一个。
All right. The fourth thing I'm going to do, is I'm going to then construct the block of code.
好,我要做的第四件事情就是,我会去写这块循环代码。
What does that say? It says if in the code up here I get an exception of that sort, I'm going to go to this place to handle it.
这意味着如果在代码中,我得到一个这样的异常,我能到这里来处理它。
That code says the following: the IF says, I've got an expression, I'm going to evaluate it.
代码的含义是这样的:,我有一个表达式,我会去对这个表达式求值。
And the code over here says, OK gee, if I'm in the base case do something.
如果我属于基础事件就进行一些操作,而我不是,所以往下看这儿。
It's okay. So this first line of code, I will get it started but then I'm gonna have you take over and actually instruct Philip what to do here.
第一行代码就从这里开始,接下来我会让你,接管并指导飞利浦。
- Writing code that just looks-- I'm not even sure what this is supposed to look like, a little flower or pinwheel or something like that.
这代码写出来有点像-,我不确定这像什么,像朵花,或纸风车,或其他什么东西。
And to do this, I'm going to use some code that I've already typed in.
为了达到这个目的,我会去使用一些,我已经写好的代码。
I'm going to use my own special program that will color code things for me in class, but the idea is the same; it's a text editor.
我将用我自己专门的程序,那个会分类为我标出代码的颜色,但是那个思想是一样的,这是一个文本编辑器。
And when I'm starting to write lots of lines of code, you know, it's frankly kind of useful to be able to see more on the screen at once without having to scroll.
当我开始写很多行代码的时候,你们懂的,这明显是有用的,当你可以在屏幕上看到更多的代码,而不用滚动屏幕。
Yeah, if my machine will come back up, there we go. So, I'm going to now go ahead and write a little piece of code, and I put it here and I hope you can actually see these better this time, let me uncomment that region.
让我们写出代码来吧,好,如果我的电脑能回来的话,好了,那么,我要去写一小块代码,我把它放在这里以期望大家这次,能看的更清楚点。
Today, I'm gonna start writing C code with you but I can't just write it and expect it to do anything.
现在,我和大家一起写C语言代码,但我不指望写出来后就能跑起来。
And in particular, if I think about that problem - actually I want to do this- if I think about that problem, I'm going to write a little piece of pseudo code.
关于这个问题尤其要注意的是,实际上当我考虑这个-,问题的时候我想这么做,我会去写一点伪代码。
stdio h This file here is called standard I/O or stdio.h and this is just another text file someone else wrote many years ago and by using that line of code there, I'm telling the computer, give me acces to this code that this other person wrote that's in that file.
在这里的头文件称为标准输入输出文件或,这是由某位前人编写的文本文件,我们只需要刚才所述的一行代码,就能告诉电脑,让我连接到,这个前人在那个文件中写的代码。
OK? And in fact, if you look at the code up here, and it's on your handout, the very first one, x 1, right here- if I could ask you to look at it-- is a piece of code to do it. And I'm less interested in the code than how we're going to analyze it, but let's look at it for a second.
实际上,如果你看看,你们课堂发的材料上面的代码,第一页上的,就是那-,大家请看看实现的这一部分代码,我不太关心,我们会怎么解释这个代码,首先让我们先看看。
Meaning, I'm just going to write a little loop that does that. All right, so let's go back to our code. That's right, let me pull this over a little bit, so I can see it. And what I'd like you to look at, I'm going to highlight it just for a second here, is those two pieces of code.
意思就是我只需,写一个小循环就可以了,让我们回到代码,让我们向下拉一点,我才看得见,我希望你看看这里。
Then we have to steal the code from earlier to do a forever loop, a while true loop and then I'm gonna go ahead and use that printf thing that we saw.
然后再借用先前的代码,做一个永久性的循环,即while循环,紧接着需要用到一个,之前我们看到过的printf函数。
So in other words, if thankful is still false at this point, it means this condition did not work out very well, and so I'm going to do this block of code again.
换句话说,如果thankful在这时候还是false值,这表示这个条件没有实现地很好,所以我将再次去处理这段代码。
So the very last two lines of code I'm saying this, s2 the original string is s1, the copy of the string is s2, but if I haven't lost you, what are we really going to see when we print this?
最后两行代码是这样的,原字符串是s1,那个字符串的拷贝是,但是如果我没有忘记,当我们打印的时候,我们将看到什么?
I'm again, iterating with this four loop, same code as before.
我再次,重复使用for循环,同样的代码。
So this code is identical functionally nonswitch c to the last implementation we saw, nonswitch.c, but I'm just ever-more emphatically saying, "In case 1," that is when n equals 1 -- or when case 2 applies -- when n equals 2 or when n equals 3 do what?
所以这些代码到最后的实现上,功能是,完全相同的,但是我想要再次强调一下,“在case,1“,那是当n等于1时1,或者当case,2适用-,当n等于2或者当n等于3,它将做什么?
That was the kind of thing you saw. Asserts said here are some conditions to test. If they're true, I'm going to let the rest of the code run.
这就是你看到的,断言是一些测试条件,如果他们为真。
The only thing I've done in this part of the program, now I'm going to go and read the code, is I've gotten the user to input a bunch of data.
现在我去读读这里的代码,是我会让用户输入一些数据,然后根据用户输入的数据。
应用推荐