Linux Shell 指令 1. ls 列出目前目錄內所有目錄與檔案 ( 不含隱藏檔 ) -a ( 含隱藏檔 ) mv test.txt.test.txt test.txt 隱藏檔 -l 列出詳細資料 d rwx r-x r-x (d: 目錄,r: 可讀,w: 可寫,x: 可執行 ) -al 2.

Similar documents
新・明解C言語入門編『索引』

新版 明解C++入門編

CC213

C 1

static struct file_operations gpio_ctl_fops={ ioctl: gpio_ctl_ioctl, open : gpio_open, release: gpio_release, ; #defineled1_on() (GPBDAT &= ~0x1) #def

CC213

ebook8-30

Microsoft Word - linux命令及建议.doc

C/C++ - 文件IO

FY.DOC

本文由筱驀釹贡献

PowerPoint 演示文稿

untitled

1 LINUX IDE Emacs gcc gdb Emacs + gcc + gdb IDE Emacs IDE C Emacs Emacs IDE ICE Integrated Computing Environment Emacs Unix Linux Emacs Emacs Emacs Un

CC213

C/C++语言 - C/C++数据

第3章.doc

投影片 1

untitled

2013 C 1 # include <stdio.h> 2 int main ( void ) 3 { 4 int cases, a, b, i; 5 scanf ("%d", & cases ); 6 for (i = 0;i < cases ;i ++) 7 { 8 scanf ("%d %d

C 1 # include <stdio.h> 2 int main ( void ) { 4 int cases, i; 5 long long a, b; 6 scanf ("%d", & cases ); 7 for (i = 0;i < cases ;i ++) 8 { 9

Microsoft Word - 在VMWare-5.5+RedHat-9下建立本机QTopia-2.1.1虚拟平台a.doc

投影片 1

The golden pins of the PCI card can be oxidized after months or years

C语言的应用.PDF

epub83-1

ebook35-2

C/C++程序设计 - 字符串与格式化输入/输出

C C

Microsoft Word 职称安排修改 于.docx

BOOL EnumWindows(WNDENUMPROC lparam); lpenumfunc, LPARAM (Native Interface) PowerBuilder PowerBuilder PBNI 2

Linux 操作系统课程社区创作

Unix®t Œ fi z.PDF

! "#$%& $()*+#$, $(-.&,./.+#/(-.&01( &-#&(&$# (&2*(,#-3.,14& $ +()5(*-#5(-#/-/#(-1#&-+)(& :;<<= > A B?

!"# $%& %!"# $%& %!"#$%& %! ( )***%% ) $)! +**+),,* -)+.* )( ) +, +*.*)+..**! )$,*)+$))$!"!#

9202reply-s.doc

C C C The Most Beautiful Language and Most Dangerous Language in the Programming World! C 2 C C C 4 C Project 30 C Project 3 60 Project 40

C++ 程式設計

nooog

C

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File

untitled

c_cpp

Microsoft Word - 实用案例.doc

Spyder Anaconda Spyder Python Spyder Python Spyder Spyder Spyder 開始 \ 所有程式 \ Anaconda3 (64-bit) \ Spyder Spyder IPython Python IPython Sp

C/C++ 语言 - 循环

untitled

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.07.doc

Andes Technology PPT Temp

Excel VBA Excel Visual Basic for Application

6 C51 ANSI C Turbo C C51 Turbo C C51 C51 C51 C51 C51 C51 C51 C51 C C C51 C51 ANSI C MCS-51 C51 ANSI C C C51 bit Byte bit sbit


第7章-并行计算.ppt

mvc

ORACLE Enterprise Linux 6.3下ORACLE11g的安装

ebook15-C

Abstract arm linux tool-chain root NET-Start! 2

C/C++语言 - 分支结构

2013 C 1 #include <stdio.h> 2 int main(void) 3 { 4 int cases, i; 5 long long a, b; 6 scanf("%d", &cases); 7 for (i = 0; i < cases; i++) 8 { 9 scanf("%

内 容 提 要 将 JAVA 开 发 环 境 迁 移 到 Linux 系 统 上 是 现 在 很 多 公 司 的 现 实 想 法, 而 在 Linux 上 配 置 JAVA 开 发 环 境 是 步 入 Linux 下 JAVA 程 序 开 发 的 第 一 步, 本 文 图 文 并 茂 地 全 程 指

chap07.key

, 即 使 是 在 昏 暗 的 灯 光 下, 她 仍 然 可 以 那 么 耀 眼 我 没 有 地 方 去, 你 会 带 着 我 么 杜 晗 像 是 在 嘲 笑 一 般, 嘴 角 的 一 抹 冷 笑 有 着 不 适 合 这 个 年 龄 的 冷 酷 和 无 情, 看 着 江 华 的 眼 神 毫 无 温

C/C++ - 数组与指针

Linux服务器构建与运维管理

《米开朗琪罗传》

epub 33-8

Microsoft PowerPoint - Class5.pptx

雲端 Cloud Computing 技術指南 運算 應用 平台與架構 10/04/15 11:55:46 INFO 10/04/15 11:55:53 INFO 10/04/15 11:55:56 INFO 10/04/15 11:56:05 INFO 10/04/15 11:56:07 INFO

mannal

<4D F736F F D20C8EDC9E82DCFC2CEE7CCE22D3039C9CF>

Microsoft Word - ACI chapter00-1ed.docx

Oracle Solaris Studio makefile C C++ Fortran IDE Solaris Linux C/C++/Fortran IDE "Project Properties" IDE makefile 1.

int *p int a 0x00C7 0x00C7 0x00C int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++;

Generated by Unregistered Batch DOC TO PDF Converter , please register! 浙江大学 C 程序设计及实验 试题卷 学年春季学期考试时间 : 2003 年 6 月 20 日上午 8:3

Transcription:

9/19 移植 (porting) 1. ARM 2. MIPS 嵌入式 (Embedded) 單一完整功能精簡, 使用 SOC 晶片 ( 系統晶片 ) RAM(DDR)/Von-Volatile Memory(Flash) CPU Speed~1GHZ <1GBytes <1GBytes 嵌入式系統 1. bootloader(assembly +c) 2. Kernel(c) 3. File system(utility)[ext2,ext3,yaffs, busybox(dhcpc/d)] 4. Usreland Application 使用者區應用程式 (c++,java) 如 :boa 嵌入式網頁伺服器 移植 跨平台編譯 (cross compiling) 跨平台編譯需要 Toolchain, 如 arm linux gcc 或 mips linux gcc gcc(x86)( 混搭 makefile)

Linux Shell 指令 1. ls 列出目前目錄內所有目錄與檔案 ( 不含隱藏檔 ) -a ( 含隱藏檔 ) mv test.txt.test.txt test.txt 隱藏檔 -l 列出詳細資料 d rwx r-x r-x (d: 目錄,r: 可讀,w: 可寫,x: 可執行 ) -al 2. chmod 更改屬性 (rwx) 指令格式 1. chmod 二進智 十進制可 1 root group user 不可 0 rwx rwx rwx Ex chmod 444 test.txt ( 可讀不可寫不可執行 ) 2. chmod +x -x +w -w +r -r ( 只有 root 有效 ) 3. mv 更改檔案 / 目錄名稱 4. cp 複製 1.cp( 空格 ) 檔案 ( 空格 ) 新檔名 2.cp( 空格 )r 目錄 ( 空格 ) 新目錄名 5. rm 刪除 1.rm( 空格 ) 檔名 2.rm( 空格 ) r( 空格 ) 目錄名 6. mkdir 建目錄 1.mkdir( 空格 ) 目錄名 2.mv( 空格 ) 檔名 ( 空格 ) 目錄名 /. 把檔案之檔案移動到目錄名之目錄內, 新檔名同原檔名 3.cp( 空格 ) 檔名 ( 空格 ) 目錄名 /. 把檔名之檔案複製到目錄名之目錄內, 新檔名同原檔名 7. 環境變數 1.PATH 可執行檔之路徑 2.LD_LIBRARY_PATH 動態程式庫路徑 3.echo $PATH 可得知可執行檔之路徑, 一般為 /bin/usr/bin 或 /usr/local/bin 或 /sbin/usr/sbin 簡單之 shell script( 手稿 ) #! /bin /bash echo $PATH

8. 設定環境變數 export 1.export 環境變數名 = 字串 ( 變數設定 ) 2.export PATH= 新加入執行路徑 : $PATH 9. pwd 列印目前工作的目錄完整路徑名稱 1..( 目前目錄 ) 2...( 上一層目錄 ) 3. ~( 使用者家目錄 ) 10. find 找檔案 1.find( 空格 ) 搜尋路徑 ( 空格 )-name( 空格 ) 檔名例 find./ -name text2.txt 11. 可以找出搜尋路徑內含有檔名之檔案之完整路徑取代檔名例 : cp / home /p304 /embedded /test.txt test2.txt 12. grep 找檔案內之某關鍵字 1.grep( 空格 )-rn( 空格 ) 關鍵字 " 搜尋路徑 r: 搜尋子路徑 n: 顯示關鍵字所在之行號例 : grep -rn embedded embedded/* gcc(gnu C Compiler) Linux C 編譯器 1.c( 空格 )-o( 空格 ) 執行檔名 ( 空格 ) 原始 C 程式碼檔名.C -o( 產生執行檔 ) 2. Wall 顯示編譯過程中所有警告 -I 檔頭檔路徑名 (header file path) 某檔頭檔所在之過程 -L 程式庫所在路徑 ( 編譯 ) 某程式庫所在路徑 -l 程式庫名 ( 連結 ) (link) 程式庫名之程式碼 ( 機械碼 ) -g 加入除錯訊息 3. gcc create static library =gcc 產生靜態 library hello.c #include <stdio.h> int main (int argc,char** argv) printf ("Hello Embedded World \n"); return;

1. 靜態程式庫 (static library) 1. 副檔名.a 2. 動態程式庫 (dyramic library) 1. 副檔名.so[. 版本 ( 主 ). 版本 ( 次 ). 版本 ( 附加 )] calc_mean.c double mean(double a,double b) return (a+b)/2.0; 3. 編譯成 libmean.a 程式庫,mean 這地方可以改變 1.gcc( 空格 )-c( 空格 )calc_mean.c -c: 只編譯會產生 obj 檔 (.o), 不會產生執行檔 calc_mean: 程式庫原始 c 程式碼檔名.c [-o( 空格 ) 指定檔名.o], 沒有指定 obj 檔名會產生與 c 程式碼相同檔各之 obj 檔 ( 如 calc_mean.o) 2.ar( 空格 )rcs( 空格 )libmean.a( 空格 )calc_mean.o r: 取代或加入 obj 檔 c: 產生程式庫 s: 加入 obj 檔之指標 3. 結果將產生 libmean.a 之程式庫 4. 寫一檔頭檔 (header) 1.double mean(double a,double b); 2. 儲存為 mean.h 5. 寫一測試 mean 副程式之程式 test_mean.c #include <stdio.h> #include "mean.h" int main (int argc,char** argv) printf ("(1+2)/2 = %f \n",mean(1.0,2.0)); return 0;

指令 gcc Wall o test_mean test_mean.c L./ -Lmean -I 檔頭檔路徑建立資料夾把檔名放入資料夾作法 gcc Wall o test_mean.c Llib lmean Iinclude 9/26 1.Linux C 編譯器 gcc 2.Linux C++ 編譯器 g++ 1.C 原始碼 a.c 存在 src 目錄 2.C 檔頭檔 a.h 存在 include 目錄, 需用 libxxx.a( 或 libxxx.so) 3. 存在 lib 目錄 4. 將 a.c 編譯程執行檔 a 1.gcc( 空格 )-Iinclude ( 空格 )a.c( 空格 )-o( 空格 ) a( 空格 )-lxxx( 空格 )-Llib -Iinclude: 檔頭檔所在目錄 a.c: 要編譯之原始碼 -o( 空格 )a: 產生執行檔, 檔名為 a -lxxx: 指定使用程式庫 5.make 指令 1. 輔助 c/c++ 編譯工具, 檔名一般為 Makefile( makefile) 2. 下指令 make 時,make 為預設執行 Makefile 內容, 若自定 Makefile 之檔名為 Makefile1 3. 下指令 make f makefile1,make 將編譯 makefile1 之內容 6.Makefile 內容 1. 語法 : 1.Target( 目的 ): 相關檔 (Tab) 指令 (Exe 1) 2. 當相關檔有變化時, 重新執行指令 Exe1, 產生新的 Target 3.C 程式碼 :hello.c 1. 執行檔 hello 2.Makefile 內容 all:hello hello:hello.c

gcc Wall hello.c o hello 3. 存為 Makefile, 下指令 make 4.Makefile 內容 ( 解說 ) 第一個目標為 all all: 子目標 1 子目標 2 make [-f 指定 Makefile 檔名 ][ 目標名 ] 解說 : Makefile: 省略時, 預設為 Makefile 目標名 : 省略時, 預設為 all Makefile all:hello hello:hello.c (Tab)gcc -Wall hello.c -o hello clean: (Tab)rm hello Makefile2 all:hello hello:hello.o (Tab)gcc -Wall hello.o -o hello hello.o:hello.c (Tab)gcc -Wall -c hello.c -o hello.o clean: (Tab)rm*.o (Tab)rm hello 解說 : hello.o--> 目標 (.o 檔 ) -c--> 必要 hello.c--> C 程式檔 -c hello.c -o hello.o--> 產生過程中之.o 檔目標 ( 執行檔 ):C 程式檔或 obj 檔 gcc -Wall C 程式檔 -o 執行檔或 gcc Wall.o 檔 -o 執行檔 1. 分類 在 src/ 目錄內建 mean 子目錄, 將 test_mean.c 移到 mean/ 目錄內

Makefile all:test_mean.c test_mean:test_mean.c (Tab)gcc -I../../include test_mean.c -o test_mean -lmean -L../../lib clean: (Tab)rm test_mean calc_mean.c double mean(double a,double b) return((a+b)/2.0); 2. 編譯 gcc Wall c calc_mean.c o calc_mean.o 成.o 檔 1. 下指令 ar rcs libmean.a calc_mean.o 2. 將產生 libmean.a 儲存到 lib/ 3. 新建 mean.h 內容 Double mean(double a,double b); 4. 儲存到 include/ ( 與前面相同 ) 3.Makefile 之變數 CFLAGS = -Wall I../../.include LDFLAGS = -L../../lib 變數名 = 字串 Makefile2 all:test_mean test_mean:test_mean.c (Tab)gcc $(CFLAGS) test_mean.c -o test_mean $(LDFLAGS) -lmean 例 CFLAGS = -Wall -I../../include LDFAGS = -L../../lib LIBS = -lmean [TARGET = test_mean] Makefile3 all:test_mean[ 或 $(TARGET)] test_mean:test_mean.c

(Tab)gcc $(CFLAGS) test_mean.c -o test_mean $(LDFLAGS) $(LIBS) clean: (Tab)rm test_mean 解說 : test_mean.c--> 相關檔案之最左邊一個檔案 ($<) test_mean--> 目標名 ($@) 4. 各檔案丟入各資料夾 src/mean Makefile2,src/mean Makefile3 10/3 一 設計加減乘除 1. 在 src/ 內建 2. calc 之子目錄 calc/ 內建 add,sub,mult,div,include 5 個子目錄 3. add/ 內建 add.c double add(double a,double b) return (a+b); 4. sub/ 內建 sub.c double sub(double a,double b) return (a-b); 5. mult/ 內建 mult.c double mult(double a,double b) return (a*b); 6. div/ 內建

div.c double div(double a,double b) return (a/b); 7.calc/ 內建 calc.c #include <stdio.h> #include "add.h" #include "sub.h" #include "mult.h" #include "div.h" void show (double res); int main(int argc,char** argv) double a,b; printf(" 請輸入 a,b 兩數 \n"); scanf("%lf %lf",&a,&b); // 當 a,b 為 double 資料 fflush(stdin); // 清除緩衝區 printf(" 請選擇運算方式,+: 加,-: 減,*: 乘,/: 除, 結束 :q(q) \n"); char op; scanf("( 空格 )%c",&op); fflush(stdin); double result; switch(op) case '+' : result = add(a,b);show(result); case '-':result = sub(a,b);show(result); case '*':result = mult(a,b);show(result); case'/': if(b==0) printf(" 除法運算時,b 不可為 0 \n");

else result=div(a,b); show(result); return 0; void show(double res) printf(" 結果 =%f \n",res); 8. 在 calc/include/ 內建 1.add.h,sub.h,mult.h,div.h 1add.h 內容 double add(double a,double b); 2sub.h 內容 double sub(double a,double b); 3mult.h 內容 double mult(double a,double b); 4div.h 內容 double div(double a,double b); 9. 在 calc 內寫 Makelife CFLAGS = -Wall -I./include all:calc calc:calc.o add.o sub.o mult.o div.o (Tab)gcc $(CFLAGS) $^ -o $@ calc.o:calc.c (Tab)gcc $(CFLAGS) -c $< -o $@ add.o:./add/add.c (Tab)gcc $(CFLAGS) -c $< -o $@ sub.o:./sub/sub.c (Tab)gcc $(CFLAGS) -c $< -o $@ mult.o:./mult/mult.c

(Tab)gcc $(CFLAGS) -c $< -o $@ div.o:./div/div.c (Tab)gcc $(CFLAGS) -c $< -o $@ clean: rm *.o rm add/*.o rm sub/*.o rm mult/*.o rm div/*.o rm calc 10. 目標 : 相關檔 (Tab) 指令 $@ = 目標名字串 $^ = 相關檔字串 $^ = 相關檔字串 $< = 相關檔字串內第一個檔名例 : calc:calc.o add.o sub.o (Tab)gcc -Wall $^ -o $@ 相當於 (Tab)gcc -Wall calc.o add.o sub.o o calc 此時 $^ = calc.o add.o sub.o $@=calc calc:calc.c add.h (Tab)gcc -Wall -c $< -o $@ gcc -Wall -c calc.c -o calc.o 此時相關檔字串 = calc.c add.h $< = calc.c $@ = calc.o 另一種寫法如下 : 程式庫一副程式之集合編輯 arithm.c int add(int a,int b) return(a+b);

int sub(int a,int b) return(a-b); int mult(int a,int b) return(a*b); double div(double a,double b) return(a/b); 編輯 arithm.h int add(int a,int b); int sub(int a,int b); int mult(int a,int b); double div(double a,double b); 使用 gcc 將 arithm.c 編譯成 arithm.o(obj 檔 ) gcc Wall c arithm.c 註 :-c 告訴 gcc 產生.o 將 arithm.o 轉成 libarithm.a 靜態程式庫 ar rcs libarithm.a arithm.o (ar rcs lib 程式庫名程式庫名.o) 輸入指令 : mkdir src cd src mdir arithm 存放 libarithm.a 之原始碼, 即 arithm.c, 編輯 arithm.c 後編譯成 libarithm.a 後存在 ~/embedded/lib 接著 cd ~/embedded/src

mkdir testarithm cd testarithm 編輯 main.c 編輯 main.c #include <stdio.h> #include arithm.h void show(double res); int main(int argc,char ** argv) double a,b; char operator; double result; char quit=0; while(quit==0) printf( 請輸入 a,b 兩數值或按 q(q) 結束 \n ); scanf( %lf %lf,&a,&b); //%lf 雙精準度格式 &a 存在到變數 a 之記憶體位置 &b 存放到變數 b 之記憶體位置 fflush(stdin); printf( 請輸入運算方式, 加 :+, 減 :-, 乘 :x, 除 :/, 結束 :q(q) \n ); scanf( ( 空白 )%c,&operator); //%c 字元 char 格式 fflush(stdin); quit=0; swith(operator) case + : result=add(a,b); show(result); //case + 結束點 case - : result=sub(a,b); show(result); case x : result=mult(a,b); show(result);

case / : if(b==0) printf( b 不可為 0 \n ); else result=div(a,b); show(result); case q : case Q : quit=1; return 0; void show(double res) //void 空回傳 printf( 結果為 %f \n,res); 編譯 main.c gcc Wall I$HOME/embedded/src/arithm L$HOME/embedded/lib o testarithm main.c larithm 10/17 計算日期輸入年月日輸出該年月日為一週內之第幾天

1. 使用 localtime 可取得目前之年 / 月 / 日 星期 / 時 / 分 / 秒 2. 計算輸入日期與今天日期之差, 差除以 7 之餘 + 今天之星期再求除 7 之餘數 3. 計算日期時需注意閏年 1 可以被 400 整除 2 不可以被 100 整除但可被 4 整除 4.tm 資料結構秒 tm_sec 0~59 分 tm_min 0~59 時 tm_hour 0~23 月內之天數 tm_mday 1~31 月 tm_mon 0~11( 從 1 月起算 ) 年 tm_year 1900 之後年份 週內之天數 tm_wday 0~6( 從星期日起算 ) 年內之天數 tm_yday 0~365( 從 1 月 1 日起算 ) [ 程式 1] 顯示現在日期時間 today.c #include <stdio.h> #include <time.h> #include <string.h> struct tm * getdate() struct tm*today=null; time_t timeval; timeval = time(null); today = localtime(&timeval); return today; // 顯示現在之年月日時分秒 int main(int argc,char ** argv) struct tm * thedate; thedate = getdate(); int year,mon,day,hour,min,sec; year = thedate->tm_year+1900; mon = thedate->tm_mon; day = thedate->tm_mday; hour = thedate->tm_hour;

min = thedate->tm_min; sec = thedate->tm_sec; char monstr[4]; char weekstr[4]; switch(mon) case 0: strcpy(monstr,"jan"); case 1: strcpy(monstr,"feb"); case 2: strcpy(monstr,"mar"); case 3: strcpy(monstr,"apr"); case 4: strcpy(monstr,"may"); case 5: strcpy(monstr,"jun"); case 6: strcpy(monstr,"jul"); case 7: strcpy(monstr,"aug"); case 8: strcpy(monstr,"sep"); case 9: strcpy(monstr,"oct"); case 10: strcpy(monstr,"nov");

case 11: strcpy(monstr,"dec"); int wday; wday = thedate->tm_wday; switch(wday) case 0:strcpy(weekstr,"Sun"); case 1:strcpy(weekstr,"Mon"); case 2:strcpy(weekstr,"Tue"); case 3:strcpy(weekstr,"Wed"); case 4:strcpy(weekstr,"Thu"); case 5:strcpy(weekstr,"Fri"); case 6:strcpy(weekstr,"Sat"); int yday yday = thedate->tm_yday int year1,mon1,day1; printf(" 現在時間 %d %s. %d %s %d:%d:%d \n",year,monstr,day,weekstr,hour,min,sec); printf(" 輸入要計算之日期 ( 年月日 )\n"); scanf("%d %d %d",&year1,&mon1,&day1); return 0; 執行 gcc Wall o today today.c./today 10/24 [ 程式 2] 判斷閏年 data.c #include <stdio.h> #include <time.h>

#include <string.h> struct tm * getdate() struct tm*today=null; time_t timeval; timeval = time(null); today = localtime(&timeval); return today; char testleap(int year) if(year % 100!=0) if(year % 4 ==0) return 1; else return 0; else if(year % 400 ==0) return 1; else return 0; int calleap(int year1,int year2) int i; int count=0; if(year1 > year2) return 0; else for(i=year1; i<=year2; i++)

count += testleap(i); return count; int pastdays(int year,int mon,int day) int count=0; int i; for(i=0; i<mon-1; i++) if(i==0 i==2 i==4 i==6 i==7 i==9) count+=31; else if(i==1) count+=(testleap(year)+28); else count+=30; count+=day; return count; int remaindays(int year,int mon,int day) int count; count = 365-pastDays(year,mon,day)+testLeap(year); return count; // 顯示現在之年月日時分秒 int main(int argc,char ** argv) struct tm * thedate; thedate = getdate(); int year,mon,day,hour,min,sec; year = thedate->tm_year+1900; mon = thedate->tm_mon; day = thedate->tm_mday;

hour = thedate->tm_hour; min = thedate->tm_min; sec = thedate->tm_sec; char monstr[4]; char weekstr[4]; switch(mon) case 0: strcpy(monstr,"jan"); case 1: strcpy(monstr,"feb"); case 2: strcpy(monstr,"mar"); case 3: strcpy(monstr,"apr"); case 4: strcpy(monstr,"may"); case 5: strcpy(monstr,"jun"); case 6: strcpy(monstr,"jul"); case 7: strcpy(monstr,"aug"); case 8: strcpy(monstr,"sep"); case 9: strcpy(monstr,"oct"); case 10:

strcpy(monstr,"nov"); case 11: strcpy(monstr,"dec"); int wday; wday = thedate->tm_wday; switch(wday) case 0:strcpy(weekstr,"Sun"); case 1:strcpy(weekstr,"Mon"); case 2:strcpy(weekstr,"Tue"); case 3:strcpy(weekstr,"Wed"); case 4:strcpy(weekstr,"Thu"); case 5:strcpy(weekstr,"Fri"); case 6:strcpy(weekstr,"Sat"); int yday; int year1,mon1,day1; yday = thedate->tm_yday; //wday2str(wday,weekstr); printf(" 現在時間 %d %s. %d(%d) %s. %d:%d:%d \n",year,monstr,day,yday,weekstr,hour,min,sec); printf(" 輸入要計算之日期 ( 年月日 )\n"); scanf("%d %d %d",&year1,&mon1,&day1); int daycount,calwday; if(year1<year) daycount=remaindays(year1,mon1,day1)\ +calleap(year+1,year-1)\ +365*(year-year-1)\ +yday+1; calwday=daycount%7; calwday=(wday-calwday+7)%7;

else if(year1>year) daycount=remaindays(year,mon+1,day)\ +calleap(year+1,year1-1)\ +365*(year1-year-1)\ +pastdays(year1,mon1,day1); calwday=daycount%7; calwday=(calwday+wday)%7; else int pdays=pastdays(year1,mon1,day1); if(pdays<(yday+1)) daycount=yday+1-pdays; calwday=daycount%7; calwday=(wday-calwday+7)%7; else daycount=pdays-yday-1; calwday=daycount%7; calwday=(calwday+wday)%7; printf("%d/%d/%d is %d \n",year1,mon1,day1,calwday); return 0; 執行 gcc Wall o data data.c./data