際際滷

際際滷Share a Scribd company logo
Argument Passing to main()
2
Passing Arguments to main( )
則 Passing Arguments to main( )
 Example: 襦蠏碁   蠍磯 語襯 豢ロ 覲

C:> myprog a b c d
program name: myprog
argument 1: a
argument 2: b
argument 3: c
argument 4: d
C:>
3
Passing Arguments to main( )
則 Passing Arguments to main( )
 C 襦蠏碁 ろ  command line 譯殊伎
arguments襯 main( ) function pass.
 argc : command line arguments 螳
 argv : arguments value襯  覦蠍  String array
[Ex] int main(int argc, char *argv[])
[Ex] myprog c java pascal
argc = 4
argv[0] => myprog
argv[1] => c
argv[2] => java
argv[3] => pascal
4
Passing Arguments to main( )
[Ex] #include <stdio.h>
int main (int argc, char *argv[]){
int count;
printf(program name: %sn, argv[0]);
if(argc > 1){
for( count=1; count < argc; count++ )
printf(argument %d = %sn, count, argv[count]);
}
else
puts(No comand line arguments);
return 0;
}
> a.out hi hello
program name: a.out
argument 1 = hi
argument 2 = hello
5
Visual C++襦 main() argument蠍
則 襦碁ゼ 襷  豺襯 蠍一牛.
6
Visual C++襦 main() argument蠍
則 Compile  Debug語 Release語
7
Visual C++襦 main() argument蠍
則 企 启襦 螳覲伎
8
Visual C++襦 main() argument蠍
則 DOS谿曙 願 企 启襦 企  ろ
Ad

Recommended

RNC C++ lecture_5 Array
RNC C++ lecture_5 Array
itlockit
RNC C++ lecture_2 operator, if
RNC C++ lecture_2 operator, if
itlockit
RNC C++ lecture_4 While, For
RNC C++ lecture_4 While, For
itlockit
14. fiile io
14. fiile io
15 3. modulization
15 3. modulization
9. pointer, pointer & function
9. pointer, pointer & function
15 3. modulization
15 3. modulization
Function pointer
Function pointer
Shih-Hsiang Lin
Ch.14 螳c v0.6
Ch.14 螳c v0.6
麹 蟾
C 語 ろ磯 02 - 企, 覦覲給, 矧
C 語 ろ磯 02 - 企, 覦覲給, 矧
Yu Yongwoo
C 語 ろ磯 01 - 蠍一
C 語 ろ磯 01 - 蠍一
Yu Yongwoo
6 function
6 function
06 矧
06 矧
HI-ARC PS 101
HI-ARC PS 101
Jae-yeol Lee
2013 C++ Study For Students #1
2013 C++ Study For Students #1
Chris Ohk
貊語拘 C&JAVA 蠍一螻殊 C襦蠏碁覦(3)
貊語拘 C&JAVA 蠍一螻殊 C襦蠏碁覦(3)
旧價拘磯
[170327 1譯殊姶]C語 A覦
[170327 1譯殊姶]C語 A覦
arundine
襦蠏碁覦 覦 れ Chap2
襦蠏碁覦 覦 れ Chap2
dktm
Basic study 4谿
Basic study 4谿
Seonmun Choi
C語 碁碁 - 矧
C語 碁碁 - 矧
SeungHyun Lee
. Ruvendix
蟆襦蠏碁覦覓 3譯殊姶
蟆襦蠏碁覦覓 3譯殊姶
Yeonah Ki
C 語 ろ磯 05 - 豢
C 語 ろ磯 05 - 豢
Yu Yongwoo
= ≡ =梶 C
= ≡ =梶 C
Heesuk Kang
13. structure
13. structure
12 2. dynamic allocation
12 2. dynamic allocation
12 1. multi-dimensional array
12 1. multi-dimensional array
11. array & pointer
11. array & pointer

More Related Content

Similar to 15 2. arguement passing to main (18)

Ch.14 螳c v0.6
Ch.14 螳c v0.6
麹 蟾
C 語 ろ磯 02 - 企, 覦覲給, 矧
C 語 ろ磯 02 - 企, 覦覲給, 矧
Yu Yongwoo
C 語 ろ磯 01 - 蠍一
C 語 ろ磯 01 - 蠍一
Yu Yongwoo
6 function
6 function
06 矧
06 矧
HI-ARC PS 101
HI-ARC PS 101
Jae-yeol Lee
2013 C++ Study For Students #1
2013 C++ Study For Students #1
Chris Ohk
貊語拘 C&JAVA 蠍一螻殊 C襦蠏碁覦(3)
貊語拘 C&JAVA 蠍一螻殊 C襦蠏碁覦(3)
旧價拘磯
[170327 1譯殊姶]C語 A覦
[170327 1譯殊姶]C語 A覦
arundine
襦蠏碁覦 覦 れ Chap2
襦蠏碁覦 覦 れ Chap2
dktm
Basic study 4谿
Basic study 4谿
Seonmun Choi
C語 碁碁 - 矧
C語 碁碁 - 矧
SeungHyun Lee
. Ruvendix
蟆襦蠏碁覦覓 3譯殊姶
蟆襦蠏碁覦覓 3譯殊姶
Yeonah Ki
C 語 ろ磯 05 - 豢
C 語 ろ磯 05 - 豢
Yu Yongwoo
= ≡ =梶 C
= ≡ =梶 C
Heesuk Kang
Ch.14 螳c v0.6
Ch.14 螳c v0.6
麹 蟾
C 語 ろ磯 02 - 企, 覦覲給, 矧
C 語 ろ磯 02 - 企, 覦覲給, 矧
Yu Yongwoo
C 語 ろ磯 01 - 蠍一
C 語 ろ磯 01 - 蠍一
Yu Yongwoo
6 function
6 function
06 矧
06 矧
2013 C++ Study For Students #1
2013 C++ Study For Students #1
Chris Ohk
貊語拘 C&JAVA 蠍一螻殊 C襦蠏碁覦(3)
貊語拘 C&JAVA 蠍一螻殊 C襦蠏碁覦(3)
旧價拘磯
[170327 1譯殊姶]C語 A覦
[170327 1譯殊姶]C語 A覦
arundine
襦蠏碁覦 覦 れ Chap2
襦蠏碁覦 覦 れ Chap2
dktm
Basic study 4谿
Basic study 4谿
Seonmun Choi
C語 碁碁 - 矧
C語 碁碁 - 矧
SeungHyun Lee
蟆襦蠏碁覦覓 3譯殊姶
蟆襦蠏碁覦覓 3譯殊姶
Yeonah Ki
C 語 ろ磯 05 - 豢
C 語 ろ磯 05 - 豢
Yu Yongwoo
= ≡ =梶 C
= ≡ =梶 C
Heesuk Kang

More from (20)

13. structure
13. structure
12 2. dynamic allocation
12 2. dynamic allocation
12 1. multi-dimensional array
12 1. multi-dimensional array
11. array & pointer
11. array & pointer
10. pointer & function
10. pointer & function
9. pointer
9. pointer
7. variable scope rule,-storage_class
7. variable scope rule,-storage_class
6. function
6. function
5 2. string processing
5 2. string processing
5 1. character processing
5 1. character processing
15 1. enumeration, typedef
15 1. enumeration, typedef
4. loop
4. loop
3 2. if statement
3 2. if statement
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib
2 3. standard io
2 3. standard io
2 2. operators
2 2. operators
2 1. variables & data types
2 1. variables & data types
Goorm ide 蟲′覯 for skku()
Goorm ide 蟲′覯 for skku()
蟲襴 蠍磯蓋 螳襭
蟲襴 蠍磯蓋 螳襭
Goorm ide 螳 殊企(蟲′ 覯)
Goorm ide 螳 殊企(蟲′ 覯)
13. structure
13. structure
12 2. dynamic allocation
12 2. dynamic allocation
12 1. multi-dimensional array
12 1. multi-dimensional array
11. array & pointer
11. array & pointer
10. pointer & function
10. pointer & function
9. pointer
9. pointer
7. variable scope rule,-storage_class
7. variable scope rule,-storage_class
6. function
6. function
5 2. string processing
5 2. string processing
5 1. character processing
5 1. character processing
15 1. enumeration, typedef
15 1. enumeration, typedef
4. loop
4. loop
3 2. if statement
3 2. if statement
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib
2 3. standard io
2 3. standard io
2 2. operators
2 2. operators
2 1. variables & data types
2 1. variables & data types
Goorm ide 蟲′覯 for skku()
Goorm ide 蟲′覯 for skku()
蟲襴 蠍磯蓋 螳襭
蟲襴 蠍磯蓋 螳襭
Goorm ide 螳 殊企(蟲′ 覯)
Goorm ide 螳 殊企(蟲′ 覯)
Ad

15 2. arguement passing to main

  • 2. 2 Passing Arguments to main( ) 則 Passing Arguments to main( ) Example: 襦蠏碁 蠍磯 語襯 豢ロ 覲 C:> myprog a b c d program name: myprog argument 1: a argument 2: b argument 3: c argument 4: d C:>
  • 3. 3 Passing Arguments to main( ) 則 Passing Arguments to main( ) C 襦蠏碁 ろ command line 譯殊伎 arguments襯 main( ) function pass. argc : command line arguments 螳 argv : arguments value襯 覦蠍 String array [Ex] int main(int argc, char *argv[]) [Ex] myprog c java pascal argc = 4 argv[0] => myprog argv[1] => c argv[2] => java argv[3] => pascal
  • 4. 4 Passing Arguments to main( ) [Ex] #include <stdio.h> int main (int argc, char *argv[]){ int count; printf(program name: %sn, argv[0]); if(argc > 1){ for( count=1; count < argc; count++ ) printf(argument %d = %sn, count, argv[count]); } else puts(No comand line arguments); return 0; } > a.out hi hello program name: a.out argument 1 = hi argument 2 = hello
  • 5. 5 Visual C++襦 main() argument蠍 則 襦碁ゼ 襷 豺襯 蠍一牛.
  • 6. 6 Visual C++襦 main() argument蠍 則 Compile Debug語 Release語
  • 7. 7 Visual C++襦 main() argument蠍 則 企 启襦 螳覲伎
  • 8. 8 Visual C++襦 main() argument蠍 則 DOS谿曙 願 企 启襦 企 ろ