|
Prev: pharmacie en ligne acomplia suisse Generique Inde acomplia belgique soft sans prescription acheter du acomplia acomplia suisse au rabais en ligne sans prescription acomplia canada sans ordonnance
Next: Error with cc sunstudio compiler
From: happytoday on 15 Apr 2008 18:36 I compiled that program under turbo C without any problems but with sunstudi I found those errors: "pnt02ma1.c", line 37: warning: implicit function declaration: system "pnt02ma1.c", line 58: operands must have arithmetic type: op "*" "pnt02ma1.c", line 58: assignment type mismatch: pointer to float "=" double "pnt02ma1.c", line 59: operands must have arithmetic type: op "/" "pnt02ma1.c", line 60: operands have incompatible types: pointer to float "-" double "pnt02ma1.c", line 61: operands must have arithmetic type: op "/" "pnt02ma1.c", line 62: operands have incompatible types: pointer to float "-" double "pnt02ma1.c", line 62: warning: improper pointer/integer combination: op "=" cc: acomp failed for pnt02ma1.c /*-----------------------pnt02ma1.c--------------------- Given those formulas ---inch = cm / 2.45 ---inch =(meter * 100)/2.45 ---feet = 12 inch ---yard = 3 feet ---yard = 36 inch ---inch = 1/12 feet ---inch = 1/36 yard ---yard > feet > inch convert given meter value to (yards , feet , and inches) 1-convert meter to the smallest unit = (inches). 2-obtain yards (biggest required value). 3-obtain the remainder inches after getting yards. m=m%36 4-obtain feet (second biggest required value). 5-obtain the remainder inches after getting feets.i=m%12 ---------------------------------------*/ #include "stdio.h" void input(float *); void conversion(float *,int *,int *,int *); void print_reults(float *,int *,int *,int *); char another(void); int main () { float meter; int yards,feet,inches; do { system("cls"); input(&meter); conversion(&meter,&yards,&feet,&inches); } while (another()=='y'); return 0; } void input(float *m) { printf("\nEnter size in meter :"); scanf("%f",m); printf("\nYou have entered size in meter %.4f\n",*m); } void conversion(m,y,f,i) float *m; int *y,*f,*i; { m=m*100.0/2.54; *y=m/36.0; m=m-(*y)*36.0; *f=m/12.0; *i=m-(*f)*12.0; printf("\n %.2f meter is = %4d yards %4d feet %4d inches ",*m,*y,*f,*i); } char another() { char a; printf("\n\n Do ou want to another procees (y/n)"); scanf("\n%c",&a); return (a); }
From: Ian Collins on 15 Apr 2008 18:51 happytoday wrote: > I compiled that program under turbo C without any problems but with > sunstudi I found those errors: > > "pnt02ma1.c", line 37: warning: implicit function declaration: system > "pnt02ma1.c", line 58: operands must have arithmetic type: op "*" > "pnt02ma1.c", line 58: assignment type mismatch: > pointer to float "=" double > "pnt02ma1.c", line 59: operands must have arithmetic type: op "/" > "pnt02ma1.c", line 60: operands have incompatible types: > pointer to float "-" double > "pnt02ma1.c", line 61: operands must have arithmetic type: op "/" > "pnt02ma1.c", line 62: operands have incompatible types: > pointer to float "-" double > "pnt02ma1.c", line 62: warning: improper pointer/integer combination: > op "=" > cc: acomp failed for pnt02ma1.c > So? These are all valid diagnostics, study them and fix the code. > > void conversion(m,y,f,i) > float *m; > int *y,*f,*i; > { Why are you using obsolete K&R functions? -- Ian Collins.
From: Andrey Tarasevich on 15 Apr 2008 18:55 happytoday wrote: > I compiled that program under turbo C without any problems but with > sunstudi I found those errors: > > "pnt02ma1.c", line 58: operands must have arithmetic type: op "*" This is the offending line m=m*100.0/2.54; where 'm' is declared as 'float*'. Not surprisingly, the compiler complains. I don't know how you managed to compile it in turbo C and, frankly, I don't believe it is possible. -- Best regards, Andrey Tarasevich
From: Jens Thoms Toerring on 15 Apr 2008 19:13 In comp.unix.programmer happytoday <ehabaziz2001(a)gmail.com> wrote: > I compiled that program under turbo C without any problems but with > sunstudi I found those errors: > "pnt02ma1.c", line 37: warning: implicit function declaration: system > "pnt02ma1.c", line 58: operands must have arithmetic type: op "*" > "pnt02ma1.c", line 58: assignment type mismatch: > pointer to float "=" double > "pnt02ma1.c", line 59: operands must have arithmetic type: op "/" > "pnt02ma1.c", line 60: operands have incompatible types: > pointer to float "-" double > "pnt02ma1.c", line 61: operands must have arithmetic type: op "/" > "pnt02ma1.c", line 62: operands have incompatible types: > pointer to float "-" double > "pnt02ma1.c", line 62: warning: improper pointer/integer combination: > op "=" > cc: acomp failed for pnt02ma1.c I somehow doubt that the program when compiled with Turbo C did anything reasonable. Most compilers are a bit more picky, which has the advantage that you get some idea what you did wrong instead of ending up with a program that does something strange. > #include "stdio.h" > void input(float *); > void conversion(float *,int *,int *,int *); > void print_reults(float *,int *,int *,int *); > char another(void); > int main () Better make that int main( void ) > { > float meter; > int yards,feet,inches; > do { > system("cls"); system(3) is declared in <stdlib.h> which you didn't include. You may also find that 'cls' isn't a command that the shell knows about, SunOS (or whatever your machine is running) is not DOS... > input(&meter); > conversion(&meter,&yards,&feet,&inches); > } while (another()=='y'); > return 0; > } > void input(float *m) > { > printf("\nEnter size in meter :"); > scanf("%f",m); Using scanf() for getting input from a user is rather difficult to get right. Just try what happens if you enter something else than a number here... > printf("\nYou have entered size in meter %.4f\n",*m); > } > void conversion(m,y,f,i) > float *m; > int *y,*f,*i; Why are you mixing the very-old style of specifying function para- meters with the "new" (but already 18 years old) way? Better use void conversion( float *m, int *y, int *f, int *i ) > { > m=m*100.0/2.54; I guess you meant *m = *m * 100.0 / 2.54; > *y=m/36.0; And here: *y = *m / 36.0; And the same in the next three lines. BTW, why do you pass pointers to the function if you don't have to? It doesn't look as if you are interested in changes to these values in the caller. > m=m-(*y)*36.0; > *f=m/12.0; > *i=m-(*f)*12.0; > printf("\n %.2f meter is = %4d yards %4d feet %4d inches",*m,*y,*f,*i); > } > char another() Also here it's better use char another( void ) > { > char a; > printf("\n\n Do ou want to another procees (y/n)"); > scanf("\n%c",&a); > return (a); > } Regards, Jens -- \ Jens Thoms Toerring ___ jt(a)toerring.de \__________________________ http://toerring.de
From: Nikos Chantziaras on 15 Apr 2008 19:31
happytoday wrote: > I compiled that program under turbo C Get rid of turbo C since it's outdated. The C language has changed considerably since then. You will not learn correct C by reading turbo C tutorials. That means programs you write are not valid C these days. |