Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C argv[]加倍并使用它进行操作_C_Double_Operations - Fatal编程技术网

C argv[]加倍并使用它进行操作

C argv[]加倍并使用它进行操作,c,double,operations,C,Double,Operations,有没有办法通过ARGV[]函数获得一个double 我已经试过了,但是它没有按照我想要的方式工作。我的“解决方案”代码是: 代码工作,但不是我想要的方式 有什么解决方案吗?以下是一些建议的更改 #include<stdio.h> #include<stdlib.h> 实际上它不起作用,因为main的参数是作为整数和字符指针数组传递的。尝试将其设置为类似您所做的其他操作只会导致未定义的行为。argv[]不是一个函数。我还不得不指出,您检查的参数太多,而不是太少……而且您不

有没有办法通过ARGV[]函数获得一个double

我已经试过了,但是它没有按照我想要的方式工作。我的“解决方案”代码是:

代码工作,但不是我想要的方式


有什么解决方案吗?

以下是一些建议的更改

#include<stdio.h>
#include<stdlib.h>

实际上它不起作用,因为
main
的参数是作为整数和字符指针数组传递的。尝试将其设置为类似您所做的其他操作只会导致未定义的行为。
argv[]
不是一个函数。我还不得不指出,您检查的参数太多,而不是太少……而且您不知道如何使用prinf()。很抱歉在代码中编写了一些错误。那是早上5点。谢谢,在解决了一些问题之后,在你的代码的帮助下,它终于起作用了。
#include<stdio.h>
#include<stdlib.h>
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);

    }

}
int main(int argc, char * argv[])

{

 // Note how arguments are passed
 MarkGenerator(argc, argv);

}