I was extremely stressed because I couldn't figure out how to pass command-line arguments to my C programs.
맥 터미널로 C 명령어 인수를 입력하는 방법을 몰라 꽤나 헤맸다. 해당 포스팅이 도움이 되길!
This is my C program.
#include <stdio.h>
int main(int argc, char *argv[])
{
int i;
printf("agrc : %d\n",argc);
printf("\n");
for (i=0; i<argc; i++)
{printf("argv[%d] : %s\n",i, argv[i]);
}
return 0;
}
1. Open the terminal and enter the following command:
gcc /Yourpath/example.c -o program #fill your program's name
> Your program will be generated with the name you specified.
2.
./program my name is Jaeeun. #Command Line Arguments
OUTPUT
agrc : 5
argv[0] : ./program
argv[1] : my
argv[2] : name
argv[3] : is
argv[4] : Jaeeun.
I hope you found this post useful :)
이 포스팅이 유용했길!