atof()和cast有什么问题? [英] what's wrong with atof() and casting?
问题描述
大家好,这对我来说真的很困惑:
#include< stdio.h>
main(int argc,char ** argv ){
printf(" argv [1] =%f\ n,(double)atof(argv [1]));
printf(" argv [1] =%d \ n \ n",atoi(argv [1]));
}
$ a.out a
argv [1] = 97.000000
argv [1] = 0
$ a.out 3
argv [1] = 0.000000
argv [1] = 3
如果没有显式转换,第一个printf()总是给出0.0。
有谁能帮我理解代码有什么问题?
谢谢您的时间,
史蒂夫
Hi everyone, this is really confusing to me:
#include <stdio.h>
main(int argc, char **argv) {
printf("argv[1] = %f\n",(double)atof(argv[1]));
printf("argv[1] = %d\n\n",atoi(argv[1]));
}
$ a.out a
argv[1] = 97.000000
argv[1] = 0
$ a.out 3
argv[1] = 0.000000
argv[1] = 3
Without explicit casting, the first printf() always gives 0.0.
Could anyone help me understand what''s wrong with the code?
Thank you for your time,
Steve
推荐答案
a.out a
argv [1] = 97.000000
argv [ 1] = 0
a.out a
argv[1] = 97.000000
argv[1] = 0
a.out 3
argv [1] = 0.000000
argv [1] = 3
如果没有明确的强制转换,第一个printf()总是给出0.0。
有谁能帮我理解代码有什么问题?
谢谢您的时间,
Steve
a.out 3
argv[1] = 0.000000
argv[1] = 3
Without explicit casting, the first printf() always gives 0.0.
Could anyone help me understand what''s wrong with the code?
Thank you for your time,
Steve
2005年6月28日星期二23:57:12 -0500,XZ< zh *** @ ews.uiuc.edu>写在
comp.lang.c:
On Tue, 28 Jun 2005 23:57:12 -0500, XZ <zh***@ews.uiuc.edu> wrote in
comp.lang.c:
大家好,这真让我感到困惑:
#include< stdio.h>
main(int argc,char ** argv){
printf(" argv [1] =%f \ n",(double)atof(argv [1])) ;
printf(" argv [1] =%d \ n \ n",atoi(argv [1]));
}
Hi everyone, this is really confusing to me:
#include <stdio.h>
main(int argc, char **argv) {
printf("argv[1] = %f\n",(double)atof(argv[1]));
printf("argv[1] = %d\n\n",atoi(argv[1]));
}
这篇关于atof()和cast有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!