C argv[] 加倍并用它操作
C argv[] to double and operate with it
有没有办法用 ARGV[] 函数得到一个双倍的值?
我试过了,但它没有按照我想要的方式工作。我的 "solution" 代码是:
int MarkGenerator(double argc, double argv[])
{
if (argc > 3){
OnError("Too few arguments for mark calculator", -3);
}
else{
double MaxPoint = argv[1];
double PointsReached = argv[2];
double temp = 0;
temp = PointsReached * MaxPoint;
printf("%d\n", temp);
temp = temp * 5;
printf("%d\n", temp);
temp = temp ++;
printf("%d\n", temp);
}
}
代码有效,但不是我想要的方式。
有什么解决办法吗?
以下是一些建议的更改。
#include<stdio.h>
#include<stdlib.h>
//argc是一个int,argv是一个char数组 *
int MarkGenerator(int argc, char * argv[])
{
if (argc < 3){
OnError("Too few arguments for mark calculator", -3);
}else{
// The function gets its arguments as strings (char *).
// Take each of the strings and convert it to double
double MaxPoint = strtod(argv[1], NULL);
double PointsReached = strtod(argv[2], NULL);
double temp = 0;
temp = PointsReached * MaxPoint;
// Use "%lf" to print a double
printf("%lf\n", temp);
temp = temp * 5;
printf("%lf\n", temp);
temp = temp ++;
printf("%lf\n", temp);
}
}
//argc是一个int,argv是一个char数组 *
// main函数的标准签名
int main(int argc, char * argv[])
{
// Note how arguments are passed
MarkGenerator(argc, argv);
}
有没有办法用 ARGV[] 函数得到一个双倍的值?
我试过了,但它没有按照我想要的方式工作。我的 "solution" 代码是:
int MarkGenerator(double argc, double argv[])
{
if (argc > 3){
OnError("Too few arguments for mark calculator", -3);
}
else{
double MaxPoint = argv[1];
double PointsReached = argv[2];
double temp = 0;
temp = PointsReached * MaxPoint;
printf("%d\n", temp);
temp = temp * 5;
printf("%d\n", temp);
temp = temp ++;
printf("%d\n", temp);
}
}
代码有效,但不是我想要的方式。
有什么解决办法吗?
以下是一些建议的更改。
#include<stdio.h>
#include<stdlib.h>
//argc是一个int,argv是一个char数组 *
int MarkGenerator(int argc, char * argv[])
{
if (argc < 3){
OnError("Too few arguments for mark calculator", -3);
}else{
// The function gets its arguments as strings (char *).
// Take each of the strings and convert it to double
double MaxPoint = strtod(argv[1], NULL);
double PointsReached = strtod(argv[2], NULL);
double temp = 0;
temp = PointsReached * MaxPoint;
// Use "%lf" to print a double
printf("%lf\n", temp);
temp = temp * 5;
printf("%lf\n", temp);
temp = temp ++;
printf("%lf\n", temp);
}
}
//argc是一个int,argv是一个char数组 *
// main函数的标准签名
int main(int argc, char * argv[])
{
// Note how arguments are passed
MarkGenerator(argc, argv);
}