本範例示範結構體的使用
如何傳遞結構體給函數,
有如物件般,把資料封裝起來.
執行如圖
由於結構太大,所以無法一一列出,故只能跳著列出,每20層一印,每層又有20筆,總執行次數為 n = 11000次,結構示意如下
<01期>
|--<01層>
| |--<10筆>
| |--<10筆>
|--<02層>
|--<10筆>
|--<10筆>
...
|--<100層>
|--<10筆>
|--<10筆>
...
<10期>
|--<01層>
| |--<10筆>
| |--<10筆>
|--<02層>
|--<10筆>
|--<10筆>
...
|--<100層>
|--<10筆>
|--<10筆>
程式碼如下
#include <conio.h>
#include <stdio.h>
#include <string.h>
char msg[128]="TC struct data test.\nby kowala... \t2011-07-26\n";
struct data{
int position[10];
int mapping[10];
};
struct node{
int period;
struct data numbers[100];
};
struct node srcNode[10]; /* 示範結構體 */
/* 畫線 */
void print_line(){printf("\n---------------------------------\n");}
/* 清結構體 */
void clrNode(struct node *map,int len){
int i,j,k;
for(i=0;i<=len;i++){
map[i].period=0;
for(j=0;j<100;j++){
for(k=0;k<10;k++){
map[i].numbers[j].position[k]=0;
map[i].numbers[j].mapping[k]=0;
}
}
}
}
/*******************************
本範例示範結構體的使用
*******************************/
void main() {
int i,j,k,n,nodeCount=10;
clrscr();
printf("%s\n",msg);
clrNode(&srcNode,nodeCount); /* 清結構體 */
n=0;
for(i=0;i<=nodeCount;i++){
printf("1-%d(%d) ",i,srcNode[i].period);
for(j=0;j<100;j++){
for(k=0;k<10;k++){
n++;
if(j%20==0 && k==0)
printf("2-%d(%d,%d) ",j,srcNode[i].numbers[j].position[k],srcNode[i].numbers[j].mapping[k]);
}
}
printf("\n");
}
printf("After %d calculation...\n",n);
print_line();
}
2011-07-26
2011-07-19
Win7 批次檔 for 寫法
我發現有些指令都沒動作了,像是以前常用的 inkey.com [1] ,現在都不行用了!
剛測試還能跑 for 迴圈,簡單寫個 Memo 起來備查。
測試 kb.exe <-- 這是我要跑的目標程式
輸入檔 input01, input02, input03 .... input20
輸出結果 01.out, 02.out, 03.out, ... 20.out
執行畫面轉向到 dbg.txt
使用了兩個批次檔,一個跑迴圈,一個帶參數執行,FOR 迴圈指令,我是寫成一行,沒換行。
go.bat
-------------------檔案開始-----------------------
@echo off
echo Debug for KB.EXE v.1.0.1 > dbg.txt
FOR %%A IN (01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20) DO call gokb input%%A %%A >> dbg.txt
del *.out
type dbg.txt
echo.
echo You can reading dbg.txt for test detail. @_@
echo.
pause
---------------------檔案結束---------------------
gokb.bat
----------------------檔案開始--------------------
@echo off
echo.
echo ========================= start %1 =========================
kb %1 %2.out
-------------------檔案結束-----------------------
在 win7 下可以跑
ASCII 表
註:
[1].inkey.com 是讀鍵值小程式,通常都是搭配 if errorlevel==27 goto xxx 來使用
製作方法如下( 27 = 0x1B = ESC )
製作 inkey.com ,由 Windows 內建的工具 debug 來製作即可,按下開始按鈕後,上面搜尋欄位輸入 cmd 再按 enter ,就會跑出命令列視窗,
輸入debug 就可以叫出如下畫面,然後依照下圖輸入組合語言指令,輸入完成後,按 Ctrl+C 中止輸入,指定長度 rcx 為 24,指定名稱 n,再寫出 w,離開 q ... 就完成了。
接受合法鍵值 ESC, 0-9, a-z, A-Z
其他鍵值會重新輸入,直到正確鍵值為止,傳回鍵值可以用 errorlevel 去接
Microsoft Windows [???? 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\aaa>debug
-a 100
1392:0100 mov ah,00
1392:0102 int 16
1392:0104 cmp al,1b
1392:0106 je 120
1392:0108 cmp al,30
1392:010A jl 0100
1392:010C cmp al,7a
1392:010E jg 100
1392:0110 cmp al,39
1392:0112 jle 120
1392:0114 cmp al,61
1392:0116 jge 120
1392:0118 cmp al,41
1392:011A jl 100
1392:011C cmp al,5a
1392:011E jg 100
1392:0120 mov ah,4c
1392:0122 int 21
1392:0124 ^C
-rcx
CX 0000
:24
-n inkey
-w
Writing 00024 bytes
-q
C:\Users\aaa>
再把它改名為 inkey.com 就能用了,但在 windows 環境中不能跑 = =,只能用在 dos 環境。
剛測試還能跑 for 迴圈,簡單寫個 Memo 起來備查。
測試 kb.exe <-- 這是我要跑的目標程式
輸入檔 input01, input02, input03 .... input20
輸出結果 01.out, 02.out, 03.out, ... 20.out
執行畫面轉向到 dbg.txt
使用了兩個批次檔,一個跑迴圈,一個帶參數執行,FOR 迴圈指令,我是寫成一行,沒換行。
go.bat
-------------------檔案開始-----------------------
@echo off
echo Debug for KB.EXE v.1.0.1 > dbg.txt
FOR %%A IN (01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20) DO call gokb input%%A %%A >> dbg.txt
del *.out
type dbg.txt
echo.
echo You can reading dbg.txt for test detail. @_@
echo.
pause
---------------------檔案結束---------------------
gokb.bat
----------------------檔案開始--------------------
@echo off
echo.
echo ========================= start %1 =========================
kb %1 %2.out
-------------------檔案結束-----------------------
在 win7 下可以跑
ASCII 表
這也是很常用的ASCII對照表:
Ref from http://www.asciitable.com/
註:
[1].inkey.com 是讀鍵值小程式,通常都是搭配 if errorlevel==27 goto xxx 來使用
製作方法如下( 27 = 0x1B = ESC )
製作 inkey.com ,由 Windows 內建的工具 debug 來製作即可,按下開始按鈕後,上面搜尋欄位輸入 cmd 再按 enter ,就會跑出命令列視窗,
輸入debug 就可以叫出如下畫面,然後依照下圖輸入組合語言指令,輸入完成後,按 Ctrl+C 中止輸入,指定長度 rcx 為 24,指定名稱 n,再寫出 w,離開 q ... 就完成了。
接受合法鍵值 ESC, 0-9, a-z, A-Z
其他鍵值會重新輸入,直到正確鍵值為止,傳回鍵值可以用 errorlevel 去接
Microsoft Windows [???? 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\aaa>debug
-a 100
1392:0100 mov ah,00
1392:0102 int 16
1392:0104 cmp al,1b
1392:0106 je 120
1392:0108 cmp al,30
1392:010A jl 0100
1392:010C cmp al,7a
1392:010E jg 100
1392:0110 cmp al,39
1392:0112 jle 120
1392:0114 cmp al,61
1392:0116 jge 120
1392:0118 cmp al,41
1392:011A jl 100
1392:011C cmp al,5a
1392:011E jg 100
1392:0120 mov ah,4c
1392:0122 int 21
1392:0124 ^C
-rcx
CX 0000
:24
-n inkey
-w
Writing 00024 bytes
-q
C:\Users\aaa>
再把它改名為 inkey.com 就能用了,但在 windows 環境中不能跑 = =,只能用在 dos 環境。
訂閱:
文章 (Atom)




