本文介绍了浮点指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 该程序没有正确地产生和回应特别是 指针(* f),(* i) in print_divide_meter_into (&米,& yds,& ft,& ins); /*--------------pnt02own.c- ----------- --- 1英寸= 2.51厘米 --- 1英寸= 2.54 / 100米 --- 1码= 3英尺 --- 1英尺= 12英寸 ---英寸=米/ 0.0254 --- feets = meter / 0.3048(0.0254 * 12) ---码=米/ 0.9144(0.0254 * 36) ---米= 1 / 0.0254 = 39.3700英寸 ---米= 1 / 0.3048 = 3.28084 FEET ---米= 1 / 0.9144 = 1.09361 YARDS ---------------------------------------------- * / #include" stdio.h" / *模块2:使用函数中的指针将尺寸输入转换为(以米为单位)到码的大小,英尺,英寸----- * / main() { 浮动计; float yds,ft,ins; char another(); system(" ; cls); 做{ input_meter(&米); divide_meter_into(& meter,& yds,& ft,& ins); print_divide_meter_into(& meter,& yds,& ft,& ins); } while(another()== ''y''); 返回0; } input_meter(float * m) { printf(&\\; \ nEnter size in meter:"); scanf("%f",&(* m)) ; printf(\ n你输入%f,* m); } divide_meter_into(浮点数) * m,float * y,float * f,float * i) { float temp_m = 0; temp_m =(* m )* 100.0 / 2.54; (* y)=(temp_m)/36.0; (temp_m)=(temp_m) - (* y)* 36.0; (* f)=(temp_m)/12.0; (* i)=(temp_m) - (* f)* 12.0; printf (\ m Meter%f = =%f码%f英尺%f 英寸,(* m),(* y),(* f),(* i)) ; } print_divide_meter_into(float * m,float * y,float * f,浮动* i) { printf(" \ n Meter%f = =%f码%f英尺%f / / $ b) $ b inches",(* m),(* y),(* f),(* i)); } char another another( ) { 字母答案; printf(\ n你想要处理(y / n)); scanf(" \ n"); scanf("%c"& answer); 返回(回答); } That program does not yield and respond correctly espcially for thepointers (*f),(*i)inprint_divide_meter_into(&meter,&yds,&ft,&ins); /*--------------pnt02own.c---------------1 inch = 2.51 cm---1 inch = 2.54/100 Meter---1 yard = 3 feet---1 feet = 12 inch---inches=meter/0.0254---feets =meter/0.3048 (0.0254 * 12)---yards =meter/0.9144 (0.0254 * 36)---meter=1/0.0254=39.3700 INCH---meter=1/0.3048=3.28084 FEET---meter=1/0.9144=1.09361 YARDS----------------------------------------------*/#include "stdio.h"/*Module 2 : using pointers in a function to convert Size Entryin meter to sizes of Yards,feet,inches-----*/main(){float meter;float yds,ft,ins;char another();system("cls");do {input_meter(&meter);divide_meter_into(&meter,&yds,&ft,&ins);print_divide_meter_into(&meter,&yds,&ft,&ins);} while (another()==''y'');return 0;} input_meter(float *m){printf("\nEnter size in meter :");scanf("%f",&(*m));printf("\nYou have Entered % f",*m);} divide_meter_into(float *m,float *y,float *f,float *i){float temp_m=0;temp_m=(*m)*100.0/2.54;(*y)=(temp_m)/36.0;(temp_m)=(temp_m)-(*y)*36.0;(*f)=(temp_m)/12.0;(*i)=(temp_m)-(*f)*12.0;printf("\n Meter %f is = %f yards %f feet %finches",(*m),(*y),(*f),(*i));} print_divide_meter_into(float *m,float *y,float *f,float *i){printf("\n Meter %f is = %f yards %f feet %finches",(*m),(*y),(*f),(*i));} char another(){char answer;printf("\n do ou want to procees (y/n)");scanf("\n");scanf("%c",&answer);return (answer);} 推荐答案 再次不必要的括号 马克麦金太尔 - ---- ==通过Newsfeeds.Com发布 - 无限制 - 无限制安全Usenet新闻== ---- http://www.newsfeeds .com 世界排名第一的新闻组服务! 120,000多个新闻组 ---- =东海岸和西海岸服务器农场 - 通过加密实现全隐私= ---- again unneccessary brackets Mark McIntyre-- ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups----= East and West-Coast Server Farms - Total Privacy via Encryption =---- 这是什么意思?你期望它做什么?实际上是什么呢?呢? 我们不介意读者。 Brian - 请为上下文引用足够的上一条消息。要从 Google执行此操作,请点击显示选项。并使用展开的 标题中显示的回复。 What does this mean? What did you expect it to do? What did it actuallydo? We aren''t mind readers. Brian --Please quote enough of the previous message for context. To do so fromGoogle, click "show options" and use the Reply shown in the expandedheader. < snip!> 你想做什么? 如果你想要整数除法,使用整数,/和%。 我认为你想要的版本: #include" stdio.h" #include" ctype.h" #include" limits.h" #define METER_PER_INCH 0.0254 typedef struct { 双米; struct { 双英寸; long int yard; unsigned char foot; } imperial; } metric_imp; int input_meter(double *米); void cleanup_stdin(void); void calculate_yfi(metric_imp * in); void print_metric_imp(metric_imp * in); int do_another(void); int main(无效) { metric_imp input = {0}; do { if(input_meter(& input.meter)){ calculate_yfi(& input); print_metric_imp(& input); } cleanup_stdin(); } while(do_another()) ; 返回0; } int input_meter(double * m) { printf(" \ nEnter)以米为单位的大小:); fflush(stdout); if(1 == scanf("%lf",m)){ 返回1; } else { fprintf(stderr,输入错误\ n); 返回0; } } void cleanup_stdin(无效) { int c; while(EOF!=(c = getchar())) if(c ==''\ n'') 休息; } void calculate_yfi(metric_imp * in) { in-> imperial.inch = in->米/ METER_PER_INCH; if(in-> imperial) .inch> = 0 && in-> imperial.inch / 36< LONG_MAX) { in-> imperial.yard = in-> imperial.inch / 36; in-> imperial .inch - = in-> imperial.yard * 36.0; in-> imperial.foot = in-> imperial.inch / 12; in- > imperial.inch - = in-> imperial.foot * 12.0; } else { in-> imperial。 yard = in-> imperial.foot = 0; } } void print_metric_imp(metric_imp * in) { printf(" \ n Meter%g is =%ld yards%d feet" "%g inches\ n", in->米,in-> imperial.yard, (int)in-> imperial.foot,in-> imperial。英寸); } int do_another(无效) { int answer; printf(\ n你想继续吗(y / n)?"); fflush(stdout); answer = getchar(); cleanup_stdin(); 返回EOF!= answer&& ''y''== tolower(回答); } - 电子邮件:我的是一个/ at / gmx / dot / de address。 <snip!> What are you trying to do?If you want integer division, use integers, "/" and "%". The version I think you want: #include "stdio.h"#include "ctype.h"#include "limits.h"#define METER_PER_INCH 0.0254typedef struct {double meter;struct {double inch;long int yard;unsigned char foot;} imperial;} metric_imp; int input_meter (double *meters);void cleanup_stdin (void);void calculate_yfi (metric_imp *in);void print_metric_imp (metric_imp *in);int do_another (void); int main (void){metric_imp input = {0}; do {if (input_meter(&input.meter)) {calculate_yfi(&input);print_metric_imp(&input);}cleanup_stdin();} while (do_another()); return 0;} int input_meter(double *m){printf("\nEnter size in meter: ");fflush(stdout);if (1 == scanf("%lf", m)) {return 1;}else {fprintf(stderr, "Input error\n");return 0;}} void cleanup_stdin (void){int c; while (EOF != (c=getchar()))if (c==''\n'')break;} void calculate_yfi (metric_imp *in){in->imperial.inch = in->meter / METER_PER_INCH; if (in->imperial.inch >= 0&& in->imperial.inch/36 < LONG_MAX){in->imperial.yard = in->imperial.inch/36;in->imperial.inch -= in->imperial.yard*36.0;in->imperial.foot = in->imperial.inch/12;in->imperial.inch -= in->imperial.foot*12.0;}else {in->imperial.yard = in->imperial.foot = 0;}} void print_metric_imp (metric_imp *in){printf("\n Meter %g is = %ld yards %d feet"" %g inches\n",in->meter, in->imperial.yard,(int)in->imperial.foot, in->imperial.inch);} int do_another (void){int answer; printf("\n Do you want to proceed (y/n)? ");fflush(stdout);answer = getchar();cleanup_stdin(); return EOF != answer && ''y'' == tolower(answer);} --E-Mail: Mine is an /at/ gmx /dot/ de address. 这篇关于浮点指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-11 05:04