Title: ?? system()
1???????????(2)
- ??????
- ???
- ??????????
- ???????
- ?? system()
???????
?????????????????
2????????
- ????????????????? ?
- "?????"????????????????
- "?????"? ?CON? (?????) ??
- ?????????????????????
- ????? ? 0lt ???????? lt ??????
- ????? ? 1gt ???????? gt ??????
- ???????? ? 2gt ??????
- ????? ?gtgt????????2gtgt??????
3?????????(1)
foo.txt ???
- Z\nyumon2gtdir gt foo.txt
- Z\nyumon2gtdir /f 2gt err.txt
- Z\nyumon2gtmore lt foo.txt
- Z\nyumon2gtmore lt err.txt
err.txt ? ?????
foo.txt ? ?????
foo.txt ? ????
Z\nyumon2gtdir /w gtgt foo.txt Z\nyumon2gtdir /v
2gtgt err.txt Z\nyumon2gtmore lt foo.txt Z\nyumon2gtm
ore lt err.txt
err.txt ??? ?????
foo.txt ? ??????
4?????????(2)
- Z\nyumon2gtdir gt con
- Z\nyumon2gtdir /f 2gt con
- Z\nyumon2gtmore lt con gt goo.txt
- abcdefghijklmnopqrstuvwxyzltEntergt
- Ctrl-zltEntergt
- Z\nyumon2gtmore lt goo.txt
????????
????? ??? goo.txt ???
???????? ????? (???p.139 ??14.3)
??????Z\nyumon2\hello ???
Z\nyumon2\hellogthello gt hello.txt Z\nyumon2\hell
ogtmore lt hello.txt
5?????
- ???????????????????????????????
- ????????????
- ????????????????????????
?????????
Z\nyumon1gtdir /s /b sort more
????/????
????/????
????
6?????????????
- more ????????
- sort ????
- find ?????
- Z\nyumon1gtdir /s find "hello"
- findstr ????????
- Z\nyumon1gtfindstr /s "fopen" .c
help ???????????
7???????
- notepad (???)
- Z\nyumon2\hellogtnotepad hello.c
- write (??????)
- Z\nyumon2\hellogtwrite
- Z\nyumon2\hellogtwrite hello.c
- devenv (????)
- Z\nyumon2\hellogtdevenv hello.c
?????
8????????????????
- hello.c ????? hello2.c ?????????
- ? CL ?????????????(cl hello2.c)
/ hello world program 2 / include
ltstdio.hgt int main(void) printf("hello
world!\n") fprintf(stderr,"error
message!\n") return 0
??????
fprintf ????????(???p.130) stderr ???????
9???????????????????
- ????????????????
- Z\nyumon2\hellogthello2
- ???
- Z\nyumon2\hellogtmore lt hello2.txt
- Z\nyumon2\hellogtmore lt err2.txt
Z\nyumon2\hellogthello2 gt hello2.txt Z\nyumon2\he
llogthello2 2gt err2.txt
Z\nyumon2\hellogthello2 gthello2.txt 2gterr2.txt
10??????????????????
- ????????? typ.c ????????????????
- (???????????1?)
CL ??????????
/ typ.c stdin type / include ltstdio.hgt int
main(void) int c while
((cfgetc(stdin)) ! EOF) fputc(c,stdout)
return 0
stdin ????c ?1?????
?????????????
stdout ?1????
fgetc() ??????1???? fputc() ?????1????
stdin ???? EOF ??????
11??????????????
- Z\nyumon2gttyp lt typ.c
- ...
- Z\nyumon2gttyp
- abc...
- abc...
- 123...
- 123...
- Z
- Z\nyumon2gtdir typ
type ????? more ????? ????????
???p.139 ??14.3??
????????? ?????????? Ctrl-c ?????
Ctrl-z ???
12???????
- ????????????????????????
- (????????????2?)
- main(void) ? main(int argc, char argv )
- int argc ??????????
- char argv ???????????
- ?
Z\nyumon2gtmainarg 1.2345 abcde
!"'() argc4 argv0"mainarg" argv1"1.2345
" argv2"abcde" argv3"!'()"
13????????????
/ mainarg.c main argument test / include
ltstdio.hgt int main(int argc, char argv)
int i printf("argc d\n", argc) for (i
0 i lt argc i) printf("argvd
\"s\"\n", i, argvi) return 0
??????? (???p.180)
14?? system( )
- ?? system( ) ??????????????????????????????????
- stdlib.h ??????
hello3.c
/ hello world program 3 / include
ltstdio.hgt include ltstdlib.hgt int main(void)
system("cls") printf("hello world!\n")
return 0
hello.c ? ??????
??????
cls ???? ??????
15????? 2
??? p.180 ?A.2
- \" 2???? \' ?????
- \t ???? \\ ????(?????????)
hello4.c
/ hello world program 4 / include
ltstdio.hgt include ltsyslib.hgt int main(void)
system("cls") printf("\\\'hello world!\'\n")
return 0
???????
16Office???????????
- Excel ???????(Excel.exe)???????????????????????
/ Excel exec program / include
ltstdio.hgt include ltstdlib.hgt int main(void)
system("\"C\\Program Files\\"
"Microsoft Office\\" "Office11\\Excel.exe
\"") return 0
excel2.c
???????????????????????????
??????????????? ??????????(\")????
Word(Winword.exe) ? PowerPoint(Powerpnt.exe)
??????????????
17?????????????????????????????
- ????????????????????? chc.c ???????
/ chc.c char counter / include ltstdio.hgt int
main(int argc, char argv) int c, cnt0
while ((cfgetc(stdin)) ! EOF) if (
) printf(" ",
) return 0
18??????? chc ????
argc 2 argv0 "chc" argv1 "i lt chc.c"
chc ????????? ????
- Z\nyumon2gtchc i lt chc.c
- i 10
- Z\nyumon2gtchc abc lt chc.c
- a 6
argc 2 argv0 "chc" argv1 "abc lt chc.c"
????????? ?????????? Ctrl-c ?????
19????????? (??????)
- excel2.c ???????????????????
- ??(excel3.c)
- ??????????????
- excel ??????? argv1 ???
- strcat ?????
- excel ??????????????
- argc 1 ?????????
- ?????????system?????