換個姿勢學 C語言
何旭輝
買這商品的人也買了...
-
$250嵌入式 Linux 系統編程
-
$880$695 -
$450$351 -
$454零基礎入門學習 Python, 2/e
-
$500$390 -
$602嵌入式 C語言自我修養 — 從芯片、編譯器到操作系統
-
$662算法訓練營:海量圖解 + 競賽刷題 (入門篇)
-
$594$564 -
$620$490 -
$360$306 -
$320$272 -
$658像C#高手一樣編程
-
$980$774 -
$588$559 -
$580$458 -
$620$484 -
$699$552 -
$720$562 -
$659$626 -
$768$730 -
$774$735 -
$479$455 -
$1,200$948 -
$780$616 -
$1,800$1,422
相關主題
商品描述
這是一本指引零基礎讀者使用C語言逐步完成一個完整項目的實踐指導書。全書以完成“外匯牌價看板”項目為目標,將編程語言基礎、程序設計及調試方法、軟件工程實踐的經驗融入其中,幫助初學者度過最艱難的入門階段。 全書共11課:編程基礎(第1~3課)介紹了什麽是程序、不同編程語言的特點、C語言程序的結構以及使用Visual Studio 2022編寫C語言程序的方法;C語言核心知識(第4~7課)從實際需求出發介紹了C語言程序中常用的數據結構,包括變量、結構體、數組等,這部分還介紹了指針、動態內存分配和文件訪問、自定義函數庫的知識;圖形用戶界面實現原理和方法(第8、9課)以在屏幕上繪制“點”為基礎,逐步介紹顯示圖形、位圖的方法和原理,並將文本界面的“外匯牌價看板”程序升級到圖形用戶界面;“外匯牌價看板”程序的完成與交付(第10、11課),在前面已完成內容的基礎上對“外匯牌價看板”進行重構,完善細節並使其達到交付標準。此外,在附錄A(電子版形式,請掃描第1頁的二維碼獲取)介紹了一些有關電腦的基礎知識。 《換個姿勢學C語言》不僅適合對學習編程感到困難的讀者,也適合那些“看了很多書,聽了很多課,但仍然沒有編程思路,不會動手寫程序”的讀者,還適合沒有編程經驗的讀者學習。
目錄大綱
·目 錄·
第1課 開始之前
1.1 為什麽很多人學不會編程 ··················1
1.2 基於應用的學習方式 ··························2
1.3 明確“外匯牌價看板”程序的設計
目標 ···················································3
1.3.1 什麽是“外匯牌價看板” ················4
1.3.2 通過需求會議確定軟件功能要求 ····6
1.3.3 編寫需求規格說明書 ························7
1.3.4 設計原型系統 ····································7
1.4 找到程序設計的思路 ··························9
1.4.1 劃分功能模塊 ····································9
1.4.2 確定程序運行的硬件環境 ··············10
1.4.3 選擇程序架構 ··································12
1.4.4 選擇程序設計語言 ··························15
1.5 小結 ·················································16
第2課 準備開發環境
2.1 軟件開發工具的組成和用途 ·············17
2.1.1 源代碼編輯器 ··································17
2.1.2 編譯器 ··············································18
2.1.3 調試器 ··············································19
2.1.4 版本管理系統 ··································19
2.2 安裝集成開發環境 ···························20
2.2.1 為何需要集成開發環境 ··················20
2.2.2 選擇集成開發環境 ··························21
2.2.3 安裝Visual Studio Community
2022 ··················································22
2.3 編寫和運行第1個C語言程序 ············26
2.3.1 規劃項目目錄結構 ··························27
2.3.2 創建解決方案和項目 ······················28
2.3.3 在空白項目中增加和運行程序 ······32
2.4 使用MSC編譯器 ······························36
2.4.1 為何使用“cpp文件” ····················36
2.4.2 設置Visual Studio中的C++項目
屬性 ··················································36
2.5 小結 ·················································38
2.6 檢查表 ·············································39
第3課 分析第1個程序
3.1 程序由多個相互調用的功能
(function)組成 ······························40
3.1.1 C語言中最基本的功能模塊被稱為
函數 ··················································41
3.1.2 “Hello,World”程序中的函數 ······41
3.1.3 通過調試工具觀察函數的調用
過程 ··················································43
3.2 定義和調用函數的方法 ····················45
3.2.1 函數從哪裡來 ··································45
3.2.2 定義和調用函數 ······························46
3.2.3 調用標準庫函數 ······························49
3.3 源程序如何“變成”可執行文件 ······57
3.3.1 預處理 ··············································58
3.3.2 編譯 ··················································59
3.3.3 鏈接 ··················································60
3.4 重復地sayHello ·······························61
換個姿勢學
C
語言
X
3.4.1 新增sayHelloForFiveTimes函數 ·····62
3.4.2 修改sayHelloForFiveTimes函數 ·····63
3.4.3 如何規範地給函數命名 ··················64
3.4.4 函數的聲明和定義的區別 ··············65
3.4.5 註釋 ··················································67
3.5 小結 ·················································68
3.6 檢查表 ·············································68
第4課 獲取和顯示外匯實時牌價
4.1 如何獲取實時牌價數據 ····················70
4.2 下載和引用外匯牌價接口庫 ·············71
4.2.1 下載外匯牌價接口庫 ······················71
4.2.2 顯示美元的中行折算價 ··················72
4.2.3 分析顯示美元中行折算價程序 ······75
4.3 數據類型與變量 ·······························78
4.3.1 數據類型與變量聲明 ······················79
4.3.2 找到變量在內存中的地址 ··············81
4.4 給變量賦值 ······································82
4.4.1 變量的初值不是默認為0 ················83
4.4.2 將常量的值賦值給變量 ··················83
4.4.3 將變量的值賦值給另一個變量 ······86
4.4.4 將算術計算的結果賦值給變量 ······87
4.4.5 將函數的返回值賦值給變量 ··········90
4.4.6 交換兩個變量的值 ··························91
4.5 選擇結構程序 ··································91
4.5.1 關系運算符和關系表達式 ··············92
4.5.2 使用if語句實現選擇結構················93
4.6 小結 ·················································96
4.7 檢查表 ·············································96
第5課 獲取完整的牌價數據
5.1 使用數組存儲數據 ···························99
5.1.1 數組的聲明方法 ····························100
5.1.2 將外匯牌價數據存入數組 ············101
5.1.3 訪問數組元素 ································102
5.1.4 突破數組大小的限制 ·····················111
5.2 處理數組中的數據 ·························126
5.2.1 查找數組中的最大值 ····················126
5.2.2 數組排序 ········································132
5.3 字符和字符串 ································141
5.3.1 電腦中的字符 ····························142
5.3.2 字符編碼 ········································143
5.3.3 編碼是如何被顯示成字符的 ········145
5.3.4 C語言中的字符 ····························148
5.3.5 從鍵盤輸入字符並顯示 ················149
5.3.6 C語言中的字符串 ·························154
5.3.7 使用scanf函數輸入字符串············159
5.4 獲取和顯示貨幣名稱 ······················160
5.4.1 獲取某種貨幣的全部牌價數據 ····161
5.4.2 分析GetRatesAndCurrencyNameBy
Code函數的原型 ····························163
5.5 小結 ···············································164
5.6 檢查表 ···········································164
第6課 創建自己的函數庫
6.1 什麽是函數庫 ································173
6.1.1 靜態鏈接庫 ····································173
6.1.2 動態鏈接庫 ····································173
6.2 自定義字符串處理函數 ··················174
6.2.1 計算字符串長度 ····························175
6.2.2 在字符串中查找特定字符的位置 178
6.2.3 轉換字符串中的大寫字母為小寫
字母 ················································181
6.2.4 復制字符串 ····································184
6.2.5 自定義字符串函數的其他要求 ····191
6.2.6 字符串處理的庫函數 ····················195
6.3 處理鍵盤輸入 ································196
目
錄
XI
6.3.1 使用scanf函數輸入數值················196
6.3.2 自定義數據輸入函數 ····················202
6.4 在Visual Studio 2022中創建
靜態庫 ···········································209
6.4.1 創建靜態庫項目 ····························209
6.4.2 函數庫中的代碼組織 ····················211
6.4.3 分發函數庫 ····································214
6.4.4 在項目中引用Mars函數庫 ············215
6.5 小結 ···············································216
6.6 檢查表 ···········································216
第7課 獲取全部外幣牌價並保存為文件
7.1 使用結構體存儲不同類型的多項
數據 ···············································222
7.1.1 定義結構體 ····································223
7.1.2 聲明結構體變量 ····························225
7.1.3 訪問結構體變量的成員 ················225
7.1.4 結構體變量的內存占用和內存
對齊 ················································227
7.1.5 使用typedef為結構體創建別名 ····231
7.1.6 獲取貨幣牌價並填充至結構體 ····232
7.2 文件訪問的基礎知識 ······················234
7.2.1 使用fopen函數打開或創建文件 ····234
7.2.2 使用fwrite函數寫入數據到文件 ·····236
7.2.3 文件緩沖區 ····································239
7.2.4 使用fread函數從磁盤文件讀入
數據 ················································240
7.3 將結構體存入磁盤文件 ··················241
7.3.1 獲取牌價數據並寫入磁盤文件 ····242
7.3.2 分析輸出文件的內容 ····················243
7.3.3 從磁盤文件讀入數據到結構體 ····247
7.4 獲取和保存全部外幣牌價數據 ·······248
7.4.1 使用結構體數組存儲多種外幣
牌價 ················································249
7.4.2 取得外幣牌價並存入結構體
數組 ················································250
7.4.3 將顯示外幣牌價的代碼封裝成
函數 ················································251
7.4.4 獲取全部外幣牌價 ························253
7.4.5 一次獲取全部牌價 ························255
7.4.6 保存和打開數據文件 ····················261
7.5 小結 ···············································266
7.6 檢查表 ···········································267
第8課 圖形編程基礎
8.1 圖像在電腦中的表示 ··················276
8.1.1 來自人工繪制的矢量圖形 ············276
8.1.2 來自數碼相機或掃描儀的位圖 ····277
8.2 電腦是如何顯示圖形的 ··············279
8.2.1 大型發光二極管顯示屏 ················280
8.2.2 OLED顯示屏 ································281
8.2.3 LCD顯示屏 ···································281
8.3 使用EasyX圖形庫··························283
8.3.1 下載和安裝EasyX圖形庫 ·············283
8.3.2 初始化圖形窗口並繪制一個白
色的點 ············································284
8.4 基本的繪圖操作 ·····························286
8.4.1 繪制線 ············································286
8.4.2 控制繪圖顏色 ································291
8.4.3 繪制和填充矩形框 ························296
8.5 小結 ···············································301
8.6 檢查表 ···········································302
第9課 顯示圖形和文本元素
9.1 常見的位圖文件格式 ······················306
9.1.1 常見的位圖格式 ····························306
換個姿勢學
C
語言
9.1.2 BMP文件基本結構························307
9.2 顯示24位BMP圖像 ························307
9.2.1 打開BMP文件並讀取文件頭········308
9.2.2 從文件中獲取第1個像素的顏色 ····317
9.2.3 繪制每個像素 ································319
9.3 優化BMP圖像顯示程序 ·················324
9.3.1 重新組織代碼結構,減少main
函數中的代碼 ································324
9.3.2 displayBMP函數的設計與實現 ····326
9.4 顯示不同字體的文字 ······················340
9.4.1 顯示文字的原理 ····························341
9.4.2 使用EasyX的函數顯示文字 ·········342
9.4.3 設置文字格式 ································343
9.5 控制屏幕分辨率和全屏顯示窗口 ····346
9.5.1 通過EnumDisplaySettings函數獲得
當前屏幕分辨率 ····························346
9.5.2 改變和恢復屏幕分辨率—
ChangeDisplaySettings ··················348
9.5.3 隱藏窗口邊框和按鈕 ····················349
9.5.4 setFullScreenWindow函數和restore
DisplayMode函數的實現 ··············350
9.6 小結 ···············································353
9.7 檢查表 ···········································353
第10課 完成外匯牌價看板程序
10.1 將程序分為三層 ···························356
10.2 設計和實現外匯牌價看板程序的
表現層 ·········································357
10.2.1 明確表現層需要完成的功能 ······358
10.2.2 創建新項目並加入工具函數 ······359
10.2.3 顯示外匯牌價看板的固定部分 ····365
10.2.4 在1頁中顯示7行牌價 ··················370
10.2.5 顯示實時外匯牌價 ······················386
10.2.6 實現分頁循環顯示 ······················391
10.2.7 其他細節問題 ······························403
10.2.8 實現按任意鍵退出 ······················410
10.3 設計和實現外匯牌價看板的數據
訪問層 ·········································414
10.3.1 設計LoadRates函數 ·····················415
10.3.2 實現LoadRates函數 ·····················417
10.3.3 顯示提示信息 ······························423
10.4 消除隱蔽的隱患 ···························427
10.4.1 排除內存泄漏 ······························427
10.4.2 請檢查網絡連接 ··························432
10.5 切換和恢復屏幕分辨率 ················440
10.6 小結 ·············································441
10.7 檢查表 ·········································441
第11課 達到交付標準
11.1 使用相對路徑 ·······························442
11.1.1 修改getFlagFileName函數 ··········444
11.1.2 修改dal.cpp ··································444
11.2 項目的配置管理 ···························444
11.2.1 Debug和Release的區別 ···············446
11.2.2 生成程序的Release版本 ··············448
11.2.3 生成外匯牌價看板程序的Release
版本 ··············································450
11.2.4 x86(Win32)和x64的區別 ·······454
11.3 製作安裝程序 ·······························455
11.3.1 安裝Microsoft Visual Studio Installer
Projects ·········································455
11.3.2 創建外匯牌價看板的安裝程序 ····457
11.3.3 安裝外匯牌價看板程序 ··············467
11.4 後續學習建議 ·······························469
11.4.1 重構外匯牌價看板程序 ··············469
11.4.2 後續學習方向及學習建議 ··········470
後記