Last active
April 5, 2024 01:40
-
-
Save lbwanghr/4c1fa8930d08f067f38dde475483ba5d to your computer and use it in GitHub Desktop.
We often encounter a situation where there are several parameters in main function, so how to use the executable file with parameter(s)?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<stdlib.h> | |
#include<math.h> | |
int main(int argc, char* argv[]){ | |
if(argc!=3){ | |
printf("Bad argument!\n"); | |
return -1; | |
} | |
double a = atof(argv[1]); | |
double n = atof(argv[2]); | |
double result = pow(a,n); | |
printf("result = %.2f\n",result); | |
return 0; | |
} | |
************************************** | |
when I want ot use the .exe file | |
win+R -> cmd -> | |
C:\Users\Administor>cd c:\ | |
c:\>Mypower.exe 2.2 3 | |
result = 10.65 | |
That's a not bad message. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do we use the return value of main function?
So when any problems occur, we could supervise the status with variable ret.