|
cbuilder에 있는 헬프를 읽어보면 다음과 같이 나와있네요.
Three parameters (arguments) are passed to main by the Borland C++Builder startup routine: argc, argv, and env.
argc, an integer, is the number of command-line arguments passed to main, including the name of the executable itself.
argv is an array of pointers to strings (char *[]).
- argv[0] is the full path name of the program being run.
- argv[1] points to the first string typed on the operating system command line after the program name.
- argv[2] points to the second string typed after the program name.
- argv[argc-1] points to the last argument passed to main.
- argv[argc] contains NULL.
//---------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#define PI 3.141595
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
double circles(int radius) {
//함수 정의하는 것은 책을 통해서 배우세요. 넘 방대해서..
double ivalue;
ivalue = radius*radius*PI;
return ivalue;
}
int main(int argc, char* argv[])
{
if (argc != 2) {
/* argc 는 자신의 프로그램명 이름을 포함하고 인수의 수까지 합한 것을
리턴 한다 usage : p2.exe 12 --> 고로 argc = 2를 리턴 */
printf("사용법은 다음과 같습니다. \n");
printf("usage : p2.exe 12 \n");
}
else {
printf("반지름%s인 원의 넓이는 %f입니다\n", argv[1],
/*argv[1]는 프로그램명 뒤에 사용자가 쓴 인수
usage : p2.exe 12 에서 12를 가르킴*/
circles(atoi(argv[1])));
/*argv[1]는 char 형 이므로 int 형으로 변환하여
함수 circles의 인수로 넘겨줌*/
}
return 0;
}
//---------------------------------------------------------------------------
조금이나마 도움이 되시길..
령이 님이 쓰신 글 :
: #include <stdio.h>
: #include <stdlib.h>
: #define PI 3.141595
:
: double circles(int radius) { <- 함수 정의 하는부분좀 자세히 설명좀 해주세요
:
: double ivalue;
: ivalue = radius*radius*PI;
:
: return ivalue;
: }
: void main(int arg, char* argv[]) {
: if (arg != 2) {
: printf("사용법은 다음과 같습니다. \n");
: printf("usage : p2.exe 12 \n")
: }
: else {
: printf("반지름%s인 원의 넓이는 %f입니다\n", argv[1],
: circles(atoi(argv[1])); <-여긴 먼가여?
: } <---%s %f 는 무슨뜻인지는 알겠는데 정확히 모르겠어여
: } <---여긴 위엣거랑 같이 }} 이렇게 더해서 쓰면 안되나여?
:
: 어제 책사서 보구있는 왕초보랍니다 이해를...몬하겠어여
: 부탁드립니다
|