c primer plus Ò»µÀÁ·Ï°Ì⣬ÇóÖú - C/C++ / CÓïÑÔ
ÌâÄ¿ÊÇ£º±àдһ¶Î³ÌÐò£¬ÒÀ´ÎÔÚÆÁÄ»ÉÏÏÔʾÃüÁîÐÐÖÐÁгöµÄËùÓÐÎļþ¡£Ê¹ÓÃargc¿ØÖÆÑ»·
£¨Write a program that sequentially displays onscreen all the files listed in the command line. Use argc to control a loop.£©
¼¸ºõÊÇÕÕ³ÍøÉϵÄÁ·Ï°Ô´´úÂ룬µ«½á¹ûÊÇ´íµÄ
C/C++ code:
1 #include <stdio.h>
2 #include <stdlib.h>
3
4
5 int main(int argc,char *argv[])
6 {
7 int byte;
8 FILE *source;
9 int filect;
10
11 if(argc==1)
12 {
13 printf("Usage: %s filename[s]\n",argv[0]);
14 exit(EXIT_FAILURE);
15 }
16
17 for(filect=1;filect<argv;filect++)
18 {
19 if((source=fopen(argv[filect],"r"))==NULL)
20 {
21 printf("Counld not open file %s for input\n",argv[filect]);
22 continue;
23 }
24
25 while((byte==getc(source))!=EOF)
26 {
27 putchar(byte);
28 // putc(byte,stdout);
29 }
30
31 if(fclose(source)!=0)
32 {
33 printf("Counld not close file %s\n",argv[1]);
34 }
35 }
36 return 0;
ubuntuÏÂÔËÐнá¹ûΪ
C/C++ code
��������������ʏ
Ïà¹ØÎÊ´ð£º
ÈçÌ⣬C/C++ÖеÄexeclÔõôµ÷ÓÃдºÃµÄjava³ÌÐò£¬
execl("/opt/java1.5/bin/java","MyClass",NULL);
ÕâÑùµÄ²»ÐÐŶ¡£
²»»á.
ÔËÐÐjava³ÌÐò
ÕÒ¹¤¾ß²é¿´Ò»ÏÂÄǸö³ÌÐòµÄÃüÁîÐÐ
ËÑË÷Ï£ºjni ......
ÔÚ¸ùĿ¼/libÖдæ·ÅÒ»¸ölog.c£¬log.h£¬²¢ÓÃÏÂÃæµÄÓï¾ä£º
gcc -c log.c
ar crv liblog.a log.o
±àÒë³öÒ»¸öliblog.a¾²Ì¬¿â£¬È»ºóÔÚÎļþ¼Ð£º/testfileÖд´½¨Ò»¸ötest.cºÍtestc.c£¬test.cÖÐÒýÓÃÁËtestc.cÖж¨ÒåµÄ·½·¨ ......
ΪʲôÎҵijÌÐòµ÷ÓÃXMLÅäÖÃÎļþÖеİ¢À²®ÎÄÏÔʾ²»³öÀ´£¿ÆäËûµÄÓïÖÖ¶¼¿ÉÒÔ£¬ÈçÖÐÎÄ£¬Ó¢ÎÄ£¬µÂÎĶ¼¿É¡£
ÎÒ½«XMLµÄ±àÂë¸ÄΪutf-8ºÍunicodeµÄµ½µÃ½á¹û¶¼Ò»Ñù.
°¢À²®ÎĵÄ×Ö¿âÄãÓÐô£¿
ÓÐ,ÎÒµÄEXEÊÇ·ÅÔÚpc»úÉÏÖ´Ðе ......
ÎÒ¸Õ°ÑÌ·ºÆÇ¿µÄµÚÈý°æµÄÊéѧÍ꣬ÎÒÖªµÀµÄÓÐC++£¬CºÍÖ¸Õë CȱÏݺÍÏÝÚå Cר¼Ò±ä³É£¬»¹ÓÐÊý¾Ý½á¹¹£¬ÎÒÏëÎÊÎÊÎÒÓ¦¸ÃÒÔʲô˳ÐòÀ´Ñ§ÄØ
CȱÏݺÍÏÝÚå Cר¼Ò±à³Ì
Êǽø½×µÄ£¬²»Óü±×Å¿´
ÖÁÓÚ
CºÍÖ¸Õë
Äã²»Àí½âÖ ......