2011-06-06 67 views

回答

4
  • 啓動提示
  • 命令運行可執行文件。如果abc.exe做: abc.exe argument1 argument2 argument3 . . . argumentn

在代碼argv[0]將包含abc.exeargv[1]將包含argument1等。 argc值將是argv

樣品串的數量

#include <stdio.h> 

int main (int argc, char *argv[]) 
{ 
    int i=0; 
    printf ("\nargc = %d", argc); 
    for (i=0; i<argc; i++) 
    { 
    printf ("\nargv[%d] = %s", i, argv[i]); 
    } 
    printf ("\n"); 
    return 0; 
} 

運行有:

demo.exe hello man this is a test

輸出:

argc = 7 
argv[0] = demo.exe 
argv[1] = hello 
argv[2] = man 
argv[3] = this 
argv[4] = is 
argv[5] = a 
argv[6] = test 

P.S:請停止使用塗rboC(3.1)

+2

爲什麼你向後打印('「\ nstuff」'與''東西\ n「')? :D – pmg 2011-06-06 18:24:09

+1

習慣,''東西\ n「'感覺像弦下面沒有土壤。 ''\ nstuff''感覺就像在保護它的字符串後面有一個堅實的基礎('\ n')。它其實是精神的。 – phoxis 2011-06-06 18:39:51

+0

哈哈!謝謝你的答案。 – pmg 2011-06-06 18:53:50

0

只是聲明你的主要的原型int main(int argc, char *argv[]),你會沒事的。 argc和argv是由操作系統(你用哪個)通過;)

+0

@downvoter:解釋你的downvote。這不正確嗎? – BlackBear 2011-06-06 17:32:15

+0

也許他是一個Windows粉絲:) – Andrei 2011-06-06 17:53:10

+0

@Andrei:ops ..他們還存在嗎? :P沒關係,會改變它=) – BlackBear 2011-06-06 17:53:53