读书笔记-2019年03月09日

今日见闻

今日重要的三件事

记录

flutter upgrade 的log记录

读书笔记-2019年03月09日


[flutter] flutter upgrade
Upgrading Flutter from /Users/panda8z/flutter...
From https://github.com/flutter/flutter
   5391447fa..8661d8aec  stable     -> origin/stable
   5391447fa..8661d8aec  beta       -> origin/beta
   5391447fa..e5b1ed7a7  dev        -> origin/dev
 + af09490e1...40c4925a5 gallery    -> origin/gallery  (forced update)
   a226c0f0d..1fa1e1a17  master     -> origin/master
 * [new branch]          revert-29010-re_enable_dart2js -> origin/revert-29010-re_enable_dart2js
 * [new tag]             v1.2.1     -> v1.2.1
 * [new tag]             v1.3.8     -> v1.3.8
 * [new tag]             v1.1.0     -> v1.1.0
 * [new tag]             v1.1.1     -> v1.1.1
 * [new tag]             v1.1.2     -> v1.1.2
 * [new tag]             v1.1.3     -> v1.1.3
 * [new tag]             v1.1.4     -> v1.1.4
 * [new tag]             v1.1.5     -> v1.1.5
 * [new tag]             v1.1.6     -> v1.1.6
 * [new tag]             v1.1.7     -> v1.1.7
 * [new tag]             v1.1.8     -> v1.1.8
 * [new tag]             v1.1.9     -> v1.1.9
 * [new tag]             v1.2.0     -> v1.2.0
 * [new tag]             v1.2.2     -> v1.2.2
 * [new tag]             v1.3.0     -> v1.3.0
 * [new tag]             v1.3.1     -> v1.3.1
 * [new tag]             v1.3.2     -> v1.3.2
 * [new tag]             v1.3.3     -> v1.3.3
 * [new tag]             v1.3.4     -> v1.3.4
 * [new tag]             v1.3.5     -> v1.3.5
 * [new tag]             v1.3.6     -> v1.3.6
 * [new tag]             v1.3.7     -> v1.3.7
Updating 5391447fa..8661d8aec
 .../app/src/main/res/mipmap-hdpi/ic_launcher.png   |  Bin 0 -> 544 bytes
 .../app/src/main/res/mipmap-mdpi/ic_launcher.png   |  Bin 0 -> 442 bytes
 .../app/src/main/res/mipmap-xhdpi/ic_launcher.png  |  Bin 0 -> 721 bytes
 .../app/src/main/res/mipmap-xxhdpi/ic_launcher.png |  Bin 0 -> 1031 bytes
 .../src/main/res/mipmap-xxxhdpi/ic_launcher.png    |  Bin 0 -> 1443 bytes
 .../AppIcon.appiconset/[email protected]   |  Bin 0 -> 11112 bytes
 .../AppIcon.appiconset/[email protected]       |  Bin 0 -> 564 bytes
 .../AppIcon.appiconset/[email protected]       |  Bin 0 -> 1283 bytes
 .../AppIcon.appiconset/[email protected]       |  Bin 0 -> 1588 bytes
 .../AppIcon.appiconset/[email protected]       |  Bin 0 -> 1025 bytes
 .../AppIcon.appiconset/[email protected]       |  Bin 0 -> 1716 bytes
 .../AppIcon.appiconset/[email protected]       |  Bin 0 -> 1920 bytes
 .../AppIcon.appiconset/[email protected]       |  Bin 0 -> 1283 bytes
 .../AppIcon.appiconset/[email protected]       |  Bin 0 -> 1895 bytes
 .../AppIcon.appiconset/[email protected]       |  Bin 0 -> 2665 bytes
 .../AppIcon.appiconset/[email protected]       |  Bin 0 -> 2665 bytes
 .../AppIcon.appiconset/[email protected]       |  Bin 0 -> 3831 bytes
 .../AppIcon.appiconset/[email protected]       |  Bin 0 -> 1888 bytes
 .../AppIcon.appiconset/[email protected]       |  Bin 0 -> 3294 bytes
 .../AppIcon.appiconset/[email protected]   |  Bin 0 -> 3612 bytes
 .../LaunchImage.imageset/LaunchImage.png           |  Bin 0 -> 68 bytes
 .../LaunchImage.imageset/[email protected]        |  Bin 0 -> 68 bytes
 .../LaunchImage.imageset/[email protected]        |  Bin 0 -> 68 bytes
 1032 files changed, 59994 insertions(+), 12240 deletions(-)

Upgrading engine...
Downloading Dart SDK from Flutter engine 3757390fa4b00d2d261bfdf5182d2e87c9113ff9...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0 71.0M    0  291k    0     0   267k      0  0:04:31  0:00:01  0:04:30  267k
  1 71.0M    1  804k    0     0   391k      0  0:03:05  0:00:02  0:03:03  391k
  2 71.0M    2 1555k    0     0   428k      0  0:02:49  0:00:03  0:02:46  428k
  2 71.0M    2 1556k    0     0   358k      0  0:03:22  0:00:04  0:03:18  358k
  2 71.0M    2 2098k    0     0   357k      0  0:03:23  0:00:05  0:03:18  362k
  2 71.0M    2 2099k    0     0   315k      0  0:03:50  0:00:06  0:03:44  325k
  4 71.0M    4 3037k    0     0   426k      0  0:02:50  0:00:07  0:02:43  440k
  5 71.0M    5 4103k    0     0   509k      0  0:02:22  0:00:08  0:02:14  576k
  7 71.0M    7 5746k    0     0   634k      0  0:01:54  0:00:09  0:01:45  889k
  9 71.0M    9 6851k    0     0   681k      0  0:01:46  0:00:10  0:01:36 1135k
 10 71.0M   10 7520k    0     0   680k      0  0:01:46  0:00:11  0:01:35 1231k
 11 71.0M   11 8332k    0     0   691k      0  0:01:45  0:00:12  0:01:33 1074k
 13 71.0M   13 9799k    0     0   750k      0  0:01:36  0:00:13  0:01:23 1138k
 15 71.0M   15 11.3M    0     0   825k      0  0:01:28  0:00:14  0:01:14 1169k
 18 71.0M   18 13.0M    0     0   889k      0  0:01:21  0:00:15  0:01:06 1307k
 21 71.0M   21 15.0M    0     0   958k      0  0:01:15  0:00:16  0:00:59 1566k
 24 71.0M   24 17.2M    0     0  1035k      0  0:01:10  0:00:17  0:00:53 1865k
 26 71.0M   26 18.9M    0     0  1072k      0  0:01:07  0:00:18  0:00:49 1910k
 28 71.0M   28 20.5M    0     0  1103k      0  0:01:05  0:00:19  0:00:46 1883k
 30 71.0M   30 21.9M    0     0  1119k      0  0:01:05  0:00:20  0:00:45 1810k
 31 71.0M   31 22.7M    0     0  1105k      0  0:01:05  0:00:21  0:00:44 1584k
 33 71.0M   33 23.8M    0     0  1107k      0  0:01:05  0:00:22  0:00:43 1350k
 35 71.0M   35 24.9M    0     0  1104k      0  0:01:05  0:00:23  0:00:42 1219k
 36 71.0M   36 25.6M    0     0  1093k      0  0:01:06  0:00:24  0:00:42 1057k
 36 71.0M   36 26.2M    0     0  1072k      0  0:01:07  0:00:25  0:00:42  884k
 37 71.0M   37 26.9M    0     0  1057k      0  0:01:08  0:00:26  0:00:42  853k
 40 71.0M   40 28.6M    0     0  1079k      0  0:01:07  0:00:27  0:00:40  962k
 43 71.0M   43 30.5M    0     0  1116k      0  0:01:05  0:00:28  0:00:37 1175k
 44 71.0M   44 31.9M    0     0  1125k      0  0:01:04  0:00:29  0:00:35 1276k
 45 71.0M   45 32.6M    0     0  1110k      0  0:01:05  0:00:30  0:00:35 1300k
 47 71.0M   47 33.4M    0     0  1101k      0  0:01:06  0:00:31  0:00:35 1333k
 48 71.0M   48 34.4M    0     0  1099k      0  0:01:06  0:00:32  0:00:34 1210k
 49 71.0M   49 35.2M    0     0  1092k      0  0:01:06  0:00:33  0:00:33  958k
 50 71.0M   50 35.8M    0     0  1076k      0  0:01:07  0:00:34  0:00:33  796k
 51 71.0M   51 36.3M    0     0  1061k      0  0:01:08  0:00:35  0:00:33  767k
 51 71.0M   51 36.8M    0     0  1047k      0  0:01:09  0:00:36  0:00:33  708k
 52 71.0M   52 37.4M    0     0  1034k      0  0:01:10  0:00:37  0:00:33  621k
 53 71.0M   53 37.7M    0     0  1015k      0  0:01:11  0:00:38  0:00:33  510k
 53 71.0M   53 38.3M    0     0  1005k      0  0:01:12  0:00:39  0:00:33  518k
 54 71.0M   54 38.7M    0     0   989k      0  0:01:13  0:00:40  0:00:33  486k
 56 71.0M   56 40.0M    0     0   997k      0  0:01:12  0:00:41  0:00:31  642k
 57 71.0M   57 41.0M    0     0   998k      0  0:01:12  0:00:42  0:00:30  732k
 59 71.0M   59 42.1M    0     0  1002k      0  0:01:12  0:00:43  0:00:29  899k
 61 71.0M   61 43.8M    0     0  1019k      0  0:01:11  0:00:44  0:00:27 1126k
 63 71.0M   63 45.0M    0     0  1024k      0  0:01:11  0:00:45  0:00:26 1302k
 64 71.0M   64 45.5M    0     0  1012k      0  0:01:11  0:00:46  0:00:25 1130k
 65 71.0M   65 46.3M    0     0  1007k      0  0:01:12  0:00:47  0:00:25 1082k
 67 71.0M   67 47.9M    0     0  1022k      0  0:01:11  0:00:48  0:00:23 1197k
 69 71.0M   69 49.6M    0     0  1035k      0  0:01:10  0:00:49  0:00:21 1179k
 71 71.0M   71 50.9M    0     0  1042k      0  0:01:09  0:00:50  0:00:19 1206k
 73 71.0M   73 52.3M    0     0  1049k      0  0:01:09  0:00:51  0:00:18 1389k
 74 71.0M   74 53.1M    0     0  1045k      0  0:01:09  0:00:52  0:00:17 1396k
 76 71.0M   76 54.0M    0     0  1044k      0  0:01:09  0:00:53  0:00:16 1249k
 77 71.0M   77 55.1M    0     0  1045k      0  0:01:09  0:00:54  0:00:15 1138k
 79 71.0M   79 56.4M    0     0  1050k      0  0:01:09  0:00:55  0:00:14 1131k
 81 71.0M   81 58.2M    0     0  1064k      0  0:01:08  0:00:56  0:00:12 1214k
 83 71.0M   83 59.2M    0     0  1062k      0  0:01:08  0:00:57  0:00:11 1247k
 84 71.0M   84 60.0M    0     0  1057k      0  0:01:08  0:00:58  0:00:10 1202k
 86 71.0M   86 61.4M    0     0  1064k      0  0:01:08  0:00:59  0:00:09 1278k
 87 71.0M   87 62.2M    0     0  1062k      0  0:01:08  0:01:00  0:00:08 1193k
 88 71.0M   88 63.0M    0     0  1057k      0  0:01:08  0:01:01  0:00:07  986k
 89 71.0M   89 63.8M    0     0  1053k      0  0:01:09  0:01:02  0:00:07  947k
 90 71.0M   90 64.6M    0     0  1050k      0  0:01:09  0:01:03  0:00:06  962k
 92 71.0M   92 65.5M    0     0  1048k      0  0:01:09  0:01:04  0:00:05  852k
 93 71.0M   93 66.4M    0     0  1046k      0  0:01:09  0:01:05  0:00:04  861k
 94 71.0M   94 67.1M    0     0  1040k      0  0:01:09  0:01:06  0:00:03  829k
 95 71.0M   95 67.8M    0     0  1035k      0  0:01:10  0:01:07  0:00:03  807k
 96 71.0M   96 68.6M    0     0  1032k      0  0:01:10  0:01:08  0:00:02  807k
 97 71.0M   97 69.3M    0     0  1028k      0  0:01:10  0:01:09  0:00:01  767k
 98 71.0M   98 69.9M    0     0  1022k      0  0:01:11  0:01:10  0:00:01  712k
 99 71.0M   99 70.5M    0     0  1016k      0  0:01:11  0:01:11 --:--:--  693k
100 71.0M  100 71.0M    0     0  1014k      0  0:01:11  0:01:11 --:--:--  712k
Building flutter tool...
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
Downloading package sky_engine...                                   1.1s
Downloading common tools...                                        29.5s
Downloading darwin-x64 tools...                                    51.1s
Downloading android-arm-profile/darwin-x64 tools...                 4.0s
Downloading android-arm-release/darwin-x64 tools...                 1.0s
Downloading android-arm64-profile/darwin-x64 tools...               2.8s
Downloading android-arm64-release/darwin-x64 tools...               3.9s
Downloading android-arm-dynamic-profile/darwin-x64 tools...         5.7s
Downloading android-arm-dynamic-release/darwin-x64 tools...         2.4s
Downloading android-arm64-dynamic-profile/darwin-x64 tools...         4.4s
Downloading android-arm64-dynamic-release/darwin-x64 tools...         2.4s
Downloading android-x86 tools...                                   13.1s
Downloading android-x64 tools...                                   11.8s
Downloading android-arm tools...                                    5.5s
Downloading android-arm-profile tools...                            2.5s
Downloading android-arm-release tools...                            3.1s
Downloading android-arm64 tools...                                  8.5s
Downloading android-arm64-profile tools...                          5.8s
Downloading android-arm64-release tools...                          3.6s
Downloading android-arm-dynamic-profile tools...                    4.4s
Downloading android-arm-dynamic-release tools...                    3.7s
Downloading android-arm64-dynamic-profile tools...                  5.2s
Downloading android-arm64-dynamic-release tools...                  5.7s
Downloading ios tools...                                           27.2s
Downloading ios-profile tools...                                   18.5s
Downloading ios-release tools...                                   16.4s

Flutter 1.0.0 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 5391447fae (3 months ago) • 2019-02-14 19:19:53 -0800
Engine • revision 3757390fa4
Tools • Dart 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

Running flutter doctor...
Doctor summary (to see all details, run flutter doctor -v):
[] Flutter (Channel stable, v1.2.1, on Mac OS X 10.14.3 18D109, locale en-CN)
[] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[] iOS toolchain - develop for iOS devices (Xcode 10.1)
[] Android Studio (version 3.2)
[] IntelliJ IDEA Ultimate Edition (version 2018.2.5)
[] VS Code (version 1.32.1)
[!] Connected device
    ! No devices available

! Doctor found issues in 1 category.
exit code 0

通过VSCode新建Flutter项目的log

读书笔记-2019年03月09日
读书笔记-2019年03月09日

读书笔记-2019年03月09日

读书笔记-2019年03月09日

[undefined] flutter create .
Waiting for another flutter command to release the startup lock...
Creating project ....
  ios/Runner.xcworkspace/contents.xcworkspacedata (created)
  ios/Runner/Info.plist (created)
  ios/Runner/Assets.xcassets/LaunchImage.imageset/[email protected] (created)
  ios/Runner/Assets.xcassets/LaunchImage.imageset/[email protected] (created)
  ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md (created)
  ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json (created)
  ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected] (created)
  ios/Runner/Base.lproj/LaunchScreen.storyboard (created)
  ios/Runner/Base.lproj/Main.storyboard (created)
  ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata (created)
  ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme (created)
  ios/Flutter/Debug.xcconfig (created)
  ios/Flutter/Release.xcconfig (created)
  ios/Flutter/AppFrameworkInfo.plist (created)
  test/widget_test.dart (created)
  panda_first.iml (created)
  .gitignore (created)
  .metadata (created)
  ios/Runner/AppDelegate.h (created)
  ios/Runner/main.m (created)
  ios/Runner/AppDelegate.m (created)
  ios/Runner.xcodeproj/project.pbxproj (created)
  android/app/src/profile/AndroidManifest.xml (created)
  android/app/src/main/res/mipmap-mdpi/ic_launcher.png (created)
  android/app/src/main/res/mipmap-hdpi/ic_launcher.png (created)
  android/app/src/main/res/drawable/launch_background.xml (created)
  android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png (created)
  android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png (created)
  android/app/src/main/res/values/styles.xml (created)
  android/app/src/main/res/mipmap-xhdpi/ic_launcher.png (created)
  android/app/src/main/AndroidManifest.xml (created)
  android/app/src/debug/AndroidManifest.xml (created)
  android/gradle/wrapper/gradle-wrapper.properties (created)
  android/gradle.properties (created)
  android/settings.gradle (created)
  pubspec.yaml (created)
  README.md (created)
  lib/main.dart (created)
  android/app/build.gradle (created)
  android/app/src/main/java/com/example/panda_first/MainActivity.java (created)
  android/build.gradle (created)
  android/panda_first_android.iml (created)
  .idea/runConfigurations/main_dart.xml (created)
  .idea/libraries/Flutter_for_Android.xml (created)
  .idea/libraries/Dart_SDK.xml (created)
  .idea/libraries/KotlinJavaRuntime.xml (created)
  .idea/modules.xml (created)
  .idea/workspace.xml (created)
Running "flutter packages get" in panda_first...                    6.5s
Wrote 66 files.

All done!
[] Flutter is fully installed. (Channel stable, v1.2.1, on Mac OS X 10.14.3 18D109, locale en-CN)
[] Android toolchain - develop for Android devices is fully installed. (Android SDK version 28.0.3)
[] iOS toolchain - develop for iOS devices is fully installed. (Xcode 10.1)
[] Android Studio is fully installed. (version 3.2)
[] IntelliJ IDEA Ultimate Edition is fully installed. (version 2018.2.5)
[] VS Code is fully installed. (version 1.32.1)
[!] Connected device is not available.

Run "flutter doctor" for information about installing additional components.

In order to run your application, type:

  $ cd .
  $ flutter run

Your application code is in ./lib/main.dart.

exit code 0

code6-1

/* summing.c -- 对用户输入的整数求和 */
#include <stdio.h>
int main(void)
{
    long num;
    long sum = 0;
    int status;

    printf("Please enter an integer to summed. ");
    printf("q to quit): ");
    status = scanf("%ld", &num);
    while (status == 1)
    {
        sum = sum + num;
        printf("Please enter next integer(q to quit): ");
        status = scanf("%ld", &num);
    }
    printf("Thos integers sum to %ld.\n", sum);
    return 0;
}

log6-1

Panda-MBP:CodeList6-1 panda8z$ gcc -o summing.out summing.c
Panda-MBP:CodeList6-1 panda8z$ ./summing.out
Please enter an integer to summed. q to quit): 8
Please enter next integer(q to quit): 09
Please enter next integer(q to quit): 89
Please enter next integer(q to quit): 89
Please enter next integer(q to quit): 89
Please enter next integer(q to quit): 1
Please enter next integer(q to quit): 1
Please enter next integer(q to quit): 2
Please enter next integer(q to quit): 3
Please enter next integer(q to quit): t
Thos integers sum to 291.
Panda-MBP:CodeList6-1 panda8z$

在模拟器上运行Flutter应用

读书笔记-2019年03月09日

CodeList 6-2 at P

code6-2

/* when.c -- 何时退出一个循环 */
#include <stdio.h>
int main(void)
{
    int n = 5;
    while (n < 7)
    {
        printf(" n = %d\n", n);
        n++;
        printf("Now n = %d\n", n);
    }

    printf("The loop has finished.\n");

    return 0;
}

log6-2

bogon:CodeList6-02 panda8z$ gcc -o when.out when.c
bogon:CodeList6-02 panda8z$ ./when.out
 n = 5
Now n = 6
 n = 6
Now n = 7
The loop has finished.
bogon:CodeList6-02 panda8z$

CodeList 6-3 at P

code6-3

/* while1.c -- 注意花括号的使用 */
/* 拙劣的代码产生了一个无限循环 */
#include <stdio.h>
int main(void)
{
    int n = 0;

    while(n < 3)
        printf("n is %d\n", n);
        n++;
    printf("That`s all this program does\n");
    return 0;
}

log6-3


n is 0
n is 0
n is 0
n is 0
n is 0
[这里省略几千行]
n is 0
n is 0
n is 0
n is 0
n is 0
n is 0
^C  //直到手动结束这个程序才得以退出.
bogon:CodeList6-03 panda8z$

CodeList 6-4 at P

code6-4

/* while2.c -- 注意分号的使用 */
#include <stdio.h>
int main (void)
{
    int n = 0;

    while(n++ < 3);
        printf("n is %d\n", n);
    printf("That`s all this program does.\n");
    return 0;
}

log6-4


bogon:CodeList6-04 panda8z$ gcc -o while2.out while2.c
while2.c:7:19: warning: while loop has empty body [-Wempty-body]
    while(n++ < 3);
                  ^
while2.c:7:19: note: put the semicolon on a separate line to silence this warning
1 warning generated.
bogon:CodeList6-04 panda8z$ ./while1.out
bash: ./while1.out: No such file or directory
bogon:CodeList6-04 panda8z$ ./while2.out
n is 4
That`s all this program does.
bogon:CodeList6-04 panda8z$

CodeList 6-5 at P

code6-5

/* cmpfit.c -- 浮点数比较 */
#include <stdio.h>
#include <math.h>
int main (void)
{
    const double ANWSER = 3.14159;
    double response;
    pirntf("What`s the value of pi?\n");
    scanf("%lf", &response);
    while(fabs(response - ANWSER) > 0.0001)
    {
        printf("Try again!\n");
        scanf("%lf", &response);
    }

    printf("Close enough!\n");
}

log6-5


bogon:CodeList6-05 panda8z$ ./cmpfit.out
What`s the value of pi?
357
Try again!
3.1416
Close enough!

CodeList 6-6 at P

code6-6

/* t_and_f.c -- C中的真和假 */
#include <stdio.h>
int main(void)
{
    int true_val, false_val;

    true_val = (10 > 2);
    false_val = (10 == 2);
    printf("true = %d, false = %d \n", true_val, false_val);
    return 0;
}

log6-6

bogon:CodeList6-06 panda8z$ gcc -o t_and_f.out t_and_f.c
bogon:CodeList6-06 panda8z$ ./t_and_f.out
true = 1, false = 0

CodeList 6-7 at P

code6-7


/* truth.c -- 哪些为真? */
#include <stdio.h>
int main (void)
{
    int n = 3;

    while(n){
        printf("%2d is true\n", n--);
    }
    printf("%2d is false\n", n);
    return 0;
}

log6-7

bogon:CodeList6-07 panda8z$ gcc -o truth.out truth.c
bogon:CodeList6-07 panda8z$ ./truth.out
 3 is true
 2 is true
 1 is true
 0 is false

CodeList 6-8 at P

code6-8

/* trouble.c -- 误用= */
#include <stdio.h>
int main(void)
{
    long num;
    long sum = 0;
    int status;

    printf("Please enter an integer to bu summed. ");
    printf("(q to quit) : ");
    status = scanf("%ld", &num);
    while(status = 1){
        sum = sum + num;
        printf("Please enter next integer (q to quit): ");
        status = scanf("%ld", &num);
    }
    printf("Those integer sum to %ld.\n", sum);
    return 0;
}

log6-8

惨不忍睹...

CodeList 6-09 at P

code6-09

// boolean.c --  使用_Bool变量

#include <stdio.h>
int main (void)
{
    long num;
    long sum = 0L;
    _Bool input_is_good;
    printf("Please enter an integer to be summed. ");
    printf("(q to quit): ");
    input_is_good = (scanf("%ld", &num) == 1);
    while(input_is_good)
    {
        sum = sum + num;
        printf("Please enter next integer (q to quit): ");
        input_is_good = (scanf("%ld", &num) == 1);
    }
    printf("Those integers sum to %ld.\n", sum);
    return 0;
}

log6-09

bogon:CodeList6-09 panda8z$ gcc -o boolean.out boolean.c
bogon:CodeList6-09 panda8z$ ./boolean.out
Please enter an integer to be summed. (q to quit): 23
Please enter next integer (q to quit): 23
Please enter next integer (q to quit): 231
Please enter next integer (q to quit): q
Those integers sum to 277.

CodeList 6-10 at P

code6-10

// sweetie1.c -- 一个计数循环
#include <stdio.h>
int main (void)
{
    const int NUMBER = 32;
    int count = 1;

    while(count <= NUMBER)
    {
        printf("Be my Valentine!\n");
        count++;
    }
    return 0;
}

log6-10


bogon:CodeList6-10 panda8z$ gcc -o sweetie1.out sweetie1.c
bogon:CodeList6-10 panda8z$ ./sweetie1.out
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
Be my Valentine!
bogon:CodeList6-10 panda8z$

CodeList 6-11 at P

code6-11

// sweetie2.c -- 一个使用for的计数循环
#include <stdio.h>
int main (void)
{
    const int NUMBER = 22;
    int count;

    for(count =1; count <= NUMBER; count++)
        printf("Be My Valentine!\n");
    return 0;
}

log6-11


bogon:CodeList6-11 panda8z$ gcc -o sweetie2.out sweetie2.c
bogon:CodeList6-11 panda8z$ ./sweetie2.out
Be My Valentine!
Be My Valentine!
Be My Valentine!
Be My Valentine!
Be My Valentine!
Be My Valentine!
Be My Valentine!
Be My Valentine!
Be My Valentine!
Be My Valentine!
Be My Valentine!
Be My Valentine!
Be My Valentine!
Be My Valentine!
Be My Valentine!
Be My Valentine!
Be My Valentine!
Be My Valentine!
Be My Valentine!
Be My Valentine!
Be My Valentine!
Be My Valentine!

CodeList 6-12 at P

code6-12

/* for_cube.c -- 使用一个for循环产生一个立方表 */
#include <stdio.h>
int main(void)
{
    int num;

    printf("    n      n cubed\n");
    for(num = 1; num < 6; num++)
    {
        printf("%5d %5d\n", num, num * num * num);
    }
    return 0;
}

log6-12

Panda-MBP:CodeList6-12 panda8z$ gcc -o for_cube.out for_cube.c
Panda-MBP:CodeList6-12 panda8z$ ./for_cube.out
    n      n cubed
    1     1
    2     8
    3    27
    4    64
    5   125

CodeList 6-13 at P

code6-13

/* postage.c -- 一类邮件资费率 */
#include <stdio.h>
int main(void )
{
    const int FIRST_OZ = 37;
    const int NEXT_OZ = 23;
    int ounces, cost;
    printf(" ounces cost\n");
    for(ounces =1, cost = FIRST_OZ; ounces <= 16; ounces++, cost += NEXT_OZ)
    {
        printf("%5d $%4.2f\n", ounces, cost/100.0);
    }
    return 0;
}

log6-13

Panda-MBP:CodeList6-13 panda8z$ gcc -o postage.out postage.c
Panda-MBP:CodeList6-13 panda8z$ ./postage.out
 ounces cost
    1 $0.37
    2 $0.60
    3 $0.83
    4 $1.06
    5 $1.29
    6 $1.52
    7 $1.75
    8 $1.98
    9 $2.21
   10 $2.44
   11 $2.67
   12 $2.90
   13 $3.13
   14 $3.36
   15 $3.59
   16 $3.82

CodeList 6-14 at P

code6-14

// zeno.c -- 序列的和
#include <stdio.h>
int main (void)
{
    int t_ct;
    double time, x;
    int limit;

    printf("Enter the number of terms you want: ");
    scanf("%d", &limit);
    for(time = 0, x =1, t_ct = 1 ; t_ct <= limit; t_ct++, x *=20)
    {
        time += 1.0/x;
        printf("time = %f when terms = %d.\n", time, t_ct);
    }
    return 0;
}

log6-14



Panda-MBP:CodeList6-14 panda8z$ gcc -o zeno.out zeno.c
Panda-MBP:CodeList6-14 panda8z$ ./zeno.out
Enter the number of terms you want: 88
time = 1.000000 when terms = 1.
time = 1.050000 when terms = 2.
time = 1.052500 when terms = 3.
time = 1.052625 when terms = 4.
time = 1.052631 when terms = 5.
time = 1.052632 when terms = 6.
time = 1.052632 when terms = 7.
time = 1.052632 when terms = 8.
time = 1.052632 when terms = 9.
time = 1.052632 when terms = 10.
time = 1.052632 when terms = 11.
time = 1.052632 when terms = 12.
time = 1.052632 when terms = 13.
time = 1.052632 when terms = 14.
time = 1.052632 when terms = 15.
time = 1.052632 when terms = 16.
time = 1.052632 when terms = 17.
time = 1.052632 when terms = 18.
time = 1.052632 when terms = 19.
time = 1.052632 when terms = 20.
time = 1.052632 when terms = 21.
time = 1.052632 when terms = 22.
time = 1.052632 when terms = 23.
time = 1.052632 when terms = 24.
time = 1.052632 when terms = 25.
time = 1.052632 when terms = 26.
time = 1.052632 when terms = 27.
time = 1.052632 when terms = 28.
time = 1.052632 when terms = 29.
time = 1.052632 when terms = 30.
time = 1.052632 when terms = 31.
time = 1.052632 when terms = 32.
time = 1.052632 when terms = 33.
time = 1.052632 when terms = 34.
time = 1.052632 when terms = 35.
time = 1.052632 when terms = 36.
time = 1.052632 when terms = 37.
time = 1.052632 when terms = 38.
time = 1.052632 when terms = 39.
time = 1.052632 when terms = 40.
time = 1.052632 when terms = 41.
time = 1.052632 when terms = 42.
time = 1.052632 when terms = 43.
time = 1.052632 when terms = 44.
time = 1.052632 when terms = 45.
time = 1.052632 when terms = 46.
time = 1.052632 when terms = 47.
time = 1.052632 when terms = 48.
time = 1.052632 when terms = 49.
time = 1.052632 when terms = 50.
time = 1.052632 when terms = 51.
time = 1.052632 when terms = 52.
time = 1.052632 when terms = 53.
time = 1.052632 when terms = 54.
time = 1.052632 when terms = 55.
time = 1.052632 when terms = 56.
time = 1.052632 when terms = 57.
time = 1.052632 when terms = 58.
time = 1.052632 when terms = 59.
time = 1.052632 when terms = 60.
time = 1.052632 when terms = 61.
time = 1.052632 when terms = 62.
time = 1.052632 when terms = 63.
time = 1.052632 when terms = 64.
time = 1.052632 when terms = 65.
time = 1.052632 when terms = 66.
time = 1.052632 when terms = 67.
time = 1.052632 when terms = 68.
time = 1.052632 when terms = 69.
time = 1.052632 when terms = 70.
time = 1.052632 when terms = 71.
time = 1.052632 when terms = 72.
time = 1.052632 when terms = 73.
time = 1.052632 when terms = 74.
time = 1.052632 when terms = 75.
time = 1.052632 when terms = 76.
time = 1.052632 when terms = 77.
time = 1.052632 when terms = 78.
time = 1.052632 when terms = 79.
time = 1.052632 when terms = 80.
time = 1.052632 when terms = 81.
time = 1.052632 when terms = 82.
time = 1.052632 when terms = 83.
time = 1.052632 when terms = 84.
time = 1.052632 when terms = 85.
time = 1.052632 when terms = 86.
time = 1.052632 when terms = 87.
time = 1.052632 when terms = 88.

CodeList 6-15 at P

code6-15

/* do_while.c -- 退出循环的条件 */
#include <stdio.h>
int main (void)
{
    const int secret_code = 13;
    int code_entered;

    do
    {
        printf("To enter the triskaidekaphobia therapy club. \n");
        printf("Please enter the secret code number:");
        scanf("%d", &code_entered);
    } while(code_entered != secret_code);

    printf("Congratulations! you are cured!\n");
    return 0;
}

log6-15

Panda-MBP:CodeList6-15 panda8z$ gcc -o do_while.out do_while.c
Panda-MBP:CodeList6-15 panda8z$ ./do_while.out
To enter the triskaidekaphobia therapy club.
Please enter the secret code number:24
To enter the triskaidekaphobia therapy club.
Please enter the secret code number:12
To enter the triskaidekaphobia therapy club.
Please enter the secret code number:233
To enter the triskaidekaphobia therapy club.
Please enter the secret code number:2444
To enter the triskaidekaphobia therapy club.
Please enter the secret code number:13
Congratulations! you are cured!

CodeList 6-16 at P

code6-16

/* entry.c -- 入口条件循环 */
#include <stdio.h>
int main(void)
{
    const int secret_code = 13;
    int code_entered;
    printf("To enter the triskaidekaphobia therapy club. \n");
    printf("Please enter the secret code number: ");
    scanf("%d", &code_entered);
    while (code_entered != secret_code)
    {
        printf("To enter the triskaidekaphobia therapy club. \n");
        printf("Please enter the secret code number: ");
        scanf("%d", &code_entered);
    }
    printf("congratulations! you are cured!\n");
    return 0;
}

log6-16

Panda-MBP:CodeList6-16 panda8z$ gcc -o entry.out entry.c
Panda-MBP:CodeList6-16 panda8z$ ./entry.out
To enter the triskaidekaphobia therapy club.
Please enter the secret code number: 234
To enter the triskaidekaphobia therapy club.
Please enter the secret code number: 12
To enter the triskaidekaphobia therapy club.
Please enter the secret code number: 12
To enter the triskaidekaphobia therapy club.
Please enter the secret code number: 12
To enter the triskaidekaphobia therapy club.
Please enter the secret code number: 22
To enter the triskaidekaphobia therapy club.
Please enter the secret code number: 33
To enter the triskaidekaphobia therapy club.
Please enter the secret code number: 13
congratulations! you are cured!

CodeList 6-17 at P

code6-17

/* rows1.c -- 使用嵌套循环 */
#include <stdio.h>
#define ROWS 6
#define CHARS 10
int main(void)
{
    int row;
    char ch;
    for (row = 0; row < ROWS; row++)
    {
        for (ch = 'A'; ch < ('A' + CHARS); ch++)
        {
            printf("%c", ch);
        }
        printf("\n");
    }
}

log6-17

Panda-MBP:CodeList6-17 panda8z$ gcc -o rows1.out rows1.c
Panda-MBP:CodeList6-17 panda8z$ ./rows1.out
ABCDEFGHIJ
ABCDEFGHIJ
ABCDEFGHIJ
ABCDEFGHIJ
ABCDEFGHIJ
ABCDEFGHIJ

CodeList 6-18 at P

code6-18

/* rows2.c -- 使用内部循环依赖于外部循环的嵌套循环 */
#include <stdio.h>
int main(void)
{
    const int ROWS = 6;
    const int CHARS = 6;

    int row;
    char ch;
    for(row = 0; row < ROWS; row++)
    {
        for(ch = ('A' + row); ch < ('A' + CHARS); ch++)
        {
            printf("%c", ch);
        }
        printf("\n");
    }
}

log6-18

Panda-MBP:CodeList6-18 panda8z$ gcc -o rows2.out rows2.c
Panda-MBP:CodeList6-18 panda8z$ ./rows2.out
ABCDEF
BCDEF
CDEF
DEF
EF
F

CodeList 6-19 at P

code6-19

/* scores_in.c -- 使用循环进行数组处理 */
#include <stdio.h>
#define SIZE 10
#define PAR 72
int main(void)
{
    int index, score[SIZE];
    int sum = 0;
    float average;

    printf("Enter %d golf scores: \n", SIZE);
    for (index = 0; index < SIZE; index++)
    {
        scanf("%d", &score[index]); //循环读入10 个分数
    }
    printf("the scores read in are as follows: \n");
    for (index = 0; index < SIZE; index++)
    {
        printf("%5d", score[index]);//验证输入
    }
    printf("\n");
    for (index = 0; index < SIZE; index++)
    {
        sum += score[index]; // 求他们的和
    }
    average = (float)sum / SIZE; // 节省时间的方法
    printf("Sum of scores = %d, average = %0.2f.\n", sum, average);
    printf("That`s a handicap of %.0f.]n", average - PAR);
    return 0;
}

log6-19

Panda-MBP:CodeList6-19 panda8z$ gcc -o scores_in.out scores_in.c
Panda-MBP:CodeList6-19 panda8z$ ./scores_in.out
Enter 10 golf scores:
3
3
3
4
4
5
56
4
2

5
the scores read in are as follows:
    3    3    3    4    4    5   56    4    2    5
Sum of scores = 89, average = 8.90.
That`s a handicap of -63.

CodeList 6-20 at P

code6-


/* power.c -- 计算数值的整数次幂 */
#include <stdio.h>
double power(double n, int p); //ANSI 原型
int main(void)
{
    double x, xpow;
    int exp;
    printf("Enter a number and the positive integer power");
    printf(" to which\nthe number will be raised. Enter q");
    printf(" to quit.\n");
    while (scanf("%lf%d", &x, &exp) == 2)
    {
        xpow = power(x, exp);
        printf("%.3g to the power %d is %.5g\n", x, exp, xpow);
        printf("Enter next pair of numbers or q to quit.\n");
    }
    printf("Hope you enjoyed ths power trip -- bye!\n");
    return 0;
}

double power(double n, int p)
{
    double pow = 1;
    int i;
    for (i = 1; i <= p; i++)
    {
        pow *= n;
    }
    return pow;
}

log6-

Panda-MBP:CodeList6-20 panda8z$ gcc -o power.out power.c
Panda-MBP:CodeList6-20 panda8z$ ./power.out
Enter a number and the positive integer power to which
the number will be raised. Enter q to quit.
3
4
3 to the power 4 is 81
Enter next pair of numbers or q to quit.
23
23
23 to the power 23 is 2.088e+31
Enter next pair of numbers or q to quit.
q
Hope you enjoyed ths power trip -- bye!