1 / 2

#include < stdio.h > int main( int argc , char * argv []) { int x, y, sum; if( argc != 3) {

a rgc , argv 의 사용방법. #include &lt; stdio.h &gt; int main( int argc , char * argv []) { int x, y, sum; if( argc != 3) { fprintf ( stderr ,&quot;Usage: %s no1 no2<br>&quot;, argv [0]); exit(1); } x = atoi ( argv [1]); y = atoi ( argv [2]); sum = x+y ;

zoie
Télécharger la présentation

#include &lt; stdio.h &gt; int main( int argc , char * argv []) { int x, y, sum; if( argc != 3) {

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. argc, argv의 사용방법 #include <stdio.h> int main(intargc, char *argv[]) { int x, y, sum; if(argc != 3) { fprintf(stderr,"Usage: %s no1 no2\n",argv[0]); exit(1); } x = atoi(argv[1]); y = atoi(argv[2]); sum = x+y; printf("%d + %d = %d \n",x,y,sum); return sum; } • 명령 실행 시 프로그램으로 인수를 넘겨주는 방법 • add.exe 프로그램을 작성 • add 4 5 를 실행하면 4+5 = 9 를 출력 • 즉 명령 실행하면서 더할 수 4와 5를 프로그램으로 넘김 • 위와 같이 하려면 옆에 있는 프로그램처럼 • intargc, char *argv[] 를 사용해야함 • argc는 argument count (인수 개수)를 의미 • argv는 argument value(인수 값)을 의미 • argc에는 명령어 총 인수개수가 들어감 • argv에는 각 인수가 문자열로 들어감 • add 4 5 (enter) 하면 argc는 3 이 들어감 • argv는 아래처럼 됨 • argv[0] = “add” • argv[1] = “4” • argv[2] = “5” • - 그러므로, 옆에 처럼 프로그램 하면 잘 동작함 add.c

  2. 실행결과

More Related