主要() [英] main()

查看:40
本文介绍了主要()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经读过除了无效之外主要的唯一参数是这个

main(int argc,char * argv [])

我可以在这个问题上是正确的。

我想从命令行提示2中取出两倍,将存储在数组中的值

传递给另一个执行某些计算的函数和

返回主函数的双精度地址。


rel.c / *来源名称* /


#include" main.h"

main.h读取为......

#include< stdio.h>

#包括< math.h>


double relstr(double * p1,double * p2);

/ * rel.c的第一行* /

main(int argc,char * argv [])

{if(argc!= 2){puts(" command error");退出(1);}

sscanf(argc,"%s",argv [1]);

double * p1 = argv [0];

double * p2 = argv [1];


我不太清楚该返回什么,我试图编译此代码

有多种形式。我总是得到sscanf()参数1的错误。应该

是某种类型的指针还是某种类型的指针?


比尔


I''ve read that the only parameters that main takes other than a void is this
main(int argc,char *argv[])
I may be correct on this.
I want to take from the command line prompt 2 doubles, pass the values
stored in the array to another function which does some calculations and
returns the address of doubles to the main function.

rel.c /* name of source */

#include "main.h"
main.h reads as thus...
#include <stdio.h>
#include <math.h>

double relstr(double *p1,double *p2);
/* first line of rel.c */
main(int argc,char *argv[])
{if (argc!=2) {puts("command error"); exit(1);}
sscanf(argc,"%s",argv[1]);
double *p1=argv[0];
double *p2=argv[1];

I''m not quite sure what to return here and I''ve tried to compile this code
in many forms. I always get an error with parameter 1 of sscanf(). Should
the be a cast to a type or pointer to or from a type somewhere?

Bill


推荐答案

Bill Cunningham写道:
Bill Cunningham wrote:
我已经读过,除了无效之外,唯一的主要参数是
main(int argc,char * argv [])
我可能在这方面是正确的。
我想从命令行提示2双打,传递存储在数组中的值
到另一个做一些计算的函数,然后把双精度的地址返回给主函数。

rel.c / *来源的名字* /

#include main.h
main.h如此读取......
#include< stdio.h>
#include< math.h>
double relstr(double * p1,double * p2);
/ * rel.c的第一行* /
main(int argc,char * argv [])
表示''是int main

{if(argc!= 2){puts(" command error");退出(1);}
你想要argc = 3

sscanf(argc,"%s",argv [1]);
这不起作用

double * p1 = argv [0];
double * p2 = argv [1];
太可怕了。你不能假装字符串是指针加倍。

我不太清楚该返回什么,我试图编译这段代码
很多形式。我总是得到sscanf()参数1的错误。应该是一个类型或指针的转换或某种类型的指针?
I''ve read that the only parameters that main takes other than a void is this
main(int argc,char *argv[])
I may be correct on this.
I want to take from the command line prompt 2 doubles, pass the values
stored in the array to another function which does some calculations and
returns the address of doubles to the main function.

rel.c /* name of source */

#include "main.h"
main.h reads as thus...
#include <stdio.h>
#include <math.h>

double relstr(double *p1,double *p2);
/* first line of rel.c */
main(int argc,char *argv[]) that''s int main
{if (argc!=2) {puts("command error"); exit(1);} you want argc = 3
sscanf(argc,"%s",argv[1]); this cannot work
double *p1=argv[0];
double *p2=argv[1]; Horrible. You can''t pretend that strings are pointers-to-double.
I''m not quite sure what to return here and I''ve tried to compile this code
in many forms. I always get an error with parameter 1 of sscanf(). Should
the be a cast to a type or pointer to or from a type somewhere?




它当然不应该被强制转换。阅读sscanf文档:你

不能传递一个整数(这是argc的类型)作为第一个参数。


我是不确定你要做什么,但是这个玩具程序可能会给你一些想法:


#include< stdio.h>

#include< stdlib.h>


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

{

double x1,x2;


if(argc!= 3){

puts(请提供两个双打);

退出(EXIT_FAILURE);

}


/ *说明了argv [0]包含的内容* /

printf("这个程序是''%s''\ n,argv [0]);


/ *如果你想要正确的错误检查,请使用strtod()* /

x1 = atof(argv [1]);

x2 = atof(argv [2]);


printf(输入的两个双打是%g和%g \ n,x1,x2);

printf("他们的总和是%g \ n,x1 + x2);


返回0;

}



It should certainly not be cast. Read the sscanf documentation: you
can''t pass an integer (which is the type of argc) as the first parameter.

I''m not sure what you''re trying to do, but this toy program might give
you some ideas:

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

int main (int argc, char *argv[])
{
double x1, x2;

if (argc != 3) {
puts("please supply two doubles");
exit(EXIT_FAILURE);
}

/* illustrates what argv[0] contains */
printf("This program is ''%s''\n", argv[0]);

/* If you want proper error-checking, use strtod() */
x1 = atof(argv[1]);
x2 = atof(argv[2]);

printf("The two doubles entered were %g and %g\n", x1, x2);
printf("Their sum is %g\n", x1 + x2);

return 0;
}


" Bill Cunningham" <无**** @ nspam.net>在消息中写道

新闻:10 ************* @ corp.supernews.com ...
"Bill Cunningham" <no****@nspam.net> wrote in message
news:10*************@corp.supernews.com...
我读过那个main除了void之外唯一的参数是
这个main(int argc,char * argv [])
我可能是正确的。
我想从命令行中获取提示2个双打,将存储在数组中的值传递给另一个执行某些计算的函数,并将双精度数地址返回给main函数。


我无法将其解析成任何合乎逻辑的东西,所以我会捅一下你想要的东西。

rel.c / *来源名称* /

#include" main.h"
main.h如此读取......
#include< stdio.h>
#include< math.h>

double relstr(double * p1,double * p2);
/ * rel.c的第一行* /
main(int argc,char * argv [])
{if(argc!= 2){puts(" command error");退出(1);}
sscanf(argc,"%s",argv [1]);
double * p1 = argv [0];
double * p2 = argv [1 ];

我不太清楚该返回什么,我试图以多种形式编译这个代码
。我总是得到sscanf()参数1的错误。应该是一个类型或指针的转换或某种类型的指针吗?
I''ve read that the only parameters that main takes other than a void is this main(int argc,char *argv[])
I may be correct on this.
I want to take from the command line prompt 2 doubles, pass the values
stored in the array to another function which does some calculations and
returns the address of doubles to the main function.
I can''t parse this into anything logical so I''ll take a stab at what I
_think_ you want.
rel.c /* name of source */

#include "main.h"
main.h reads as thus...
#include <stdio.h>
#include <math.h>

double relstr(double *p1,double *p2);
/* first line of rel.c */
main(int argc,char *argv[])
{if (argc!=2) {puts("command error"); exit(1);}
sscanf(argc,"%s",argv[1]);
double *p1=argv[0];
double *p2=argv[1];

I''m not quite sure what to return here and I''ve tried to compile this code
in many forms. I always get an error with parameter 1 of sscanf(). Should
the be a cast to a type or pointer to or from a type somewhere?




您的意思是:


/ * rel.c * /

#include< stdio.h>

#include< stdlib.h>


double relstr(double d1,double d2);


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


double d1,d2,d3;


if(argc!= 3){

puts(command error);

退出(EXIT_FAILURE);

}


d1 = strtod(argv [1],NULL);

d2 = strtod(argv [2],NULL);


d3 = relstr(d1,d2);


/ *无论你需要什么要做* /


退出(EXIT_SUCCESS);

}


-

Stephen Sprunk愚蠢的人用智能环绕自己

CCIE#3723人。聪明的人围绕着他们自己与他们不同意的K5SSS聪明人。 --Aaron Sorkin



Did you mean:

/* rel.c */
#include <stdio.h>
#include <stdlib.h>

double relstr(double d1, double d2);

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

double d1, d2, d3;

if (argc != 3) {
puts("command error");
exit(EXIT_FAILURE);
}

d1 = strtod(argv[1], NULL);
d2 = strtod(argv[2], NULL);

d3 = relstr(d1, d2);

/* whatever else you need to do */

exit(EXIT_SUCCESS);
}

--
Stephen Sprunk "Stupid people surround themselves with smart
CCIE #3723 people. Smart people surround themselves with
K5SSS smart people who disagree with them." --Aaron Sorkin


>我无法将其解析成任何符合逻辑的东西,所以我会对我想要的
> I can''t parse this into anything logical so I''ll take a stab at what I
_think_进行抨击。
_think_ you want.
rel.c / *来源名称* /

#include" main.h"
main.h如此读取......
#include< stdio.h>
#include< math.h>

double relstr(double * p1,double * p2);
/ * rel.c * /
main的第一行(int argc ,char * argv [])
{if(argc!= 2){puts(" command error");退出(1);}
sscanf(argc,"%s",argv [1]);
double * p1 = argv [0];
double * p2 = argv [1 ];

我不太清楚该返回什么,我试图以多种形式编译这个
代码。我总是得到sscanf()参数1的错误。
应该是某种类型或指针的类型或指针转换器吗?
rel.c /* name of source */

#include "main.h"
main.h reads as thus...
#include <stdio.h>
#include <math.h>

double relstr(double *p1,double *p2);
/* first line of rel.c */
main(int argc,char *argv[])
{if (argc!=2) {puts("command error"); exit(1);}
sscanf(argc,"%s",argv[1]);
double *p1=argv[0];
double *p2=argv[1];

I''m not quite sure what to return here and I''ve tried to compile this code in many forms. I always get an error with parameter 1 of sscanf(). Should the be a cast to a type or pointer to or from a type somewhere?



你的意思是:

/ * rel.c * /
#include< stdio.h>
#include< stdlib.h>

double relstr(double d1,double d2);

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

双d1,d2,d3;

if(argc!= 3){
puts(command error);
exit(EXIT_FAILURE);
}

d1 = strtod(argv [1],NULL);
d2 = strtod (argv [2],NULL);

d3 = relstr(d1,d2);

/ *其他任何你需要做的事情* /

exit(EXIT_SUCCESS);
}



Did you mean:

/* rel.c */
#include <stdio.h>
#include <stdlib.h>

double relstr(double d1, double d2);

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

double d1, d2, d3;

if (argc != 3) {
puts("command error");
exit(EXIT_FAILURE);
}

d1 = strtod(argv[1], NULL);
d2 = strtod(argv[2], NULL);

d3 = relstr(d1, d2);

/* whatever else you need to do */

exit(EXIT_SUCCESS);
}



我对stdlib库函数还不熟悉。如果我正在使用的教程得到那里,我将不得不学习它们。我想这是串起来

double。正是我需要的。我需要超越stdio.h。谢谢。


比尔


I''m not familiar yet with the stdlib library functions. I''ll have to
study them if the tutorial I''m using gets there.stod() I guess is string to
double. Just what I need. I need to get beyond stdio.h. Thanks.

Bill


这篇关于主要()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆