error when rename pointer names

E

ehabaziz2001

When I rename the variables d,p TO : do,po in all the module of :
void convert_meter(float *me,float *d,float *p)
I got an error of that line of : void convert_meter(float *me,float
*d,float *p)

E:\programs\c_lang\iti01\tc201\ch05\own>tcc pnt02o04
Turbo C Version 2.01 Copyright (c) 1987, 1988 Borland International
pnt02o04.c:
Error pnt02o04.c 44: Declaration syntax error
*** 1 errors in Compile ***

Available memory 396264


#include "stdio.h"

void main()
{
float meter,dots,points;
void input_meter();
void convert_meter();
char another();
do {
input_meter(&meter);
convert_meter(&meter,&dots,&points);
} while (another()=='y');
}


void input_meter(float *me)
{
printf("\nEnter size in meter : ");
scanf("%f",me);
}

void convert_meter(float *me,float *d,float *p)
{
*d=((*me)*300)/(0.0254);
*p=((*me)*720)/(0.0254);
printf("\n %f Meter is = %f dots %f points",*me,*d,*p);
}


char another()
{
char ans;
printf("\n\n Do you want to procees (y/n) : ");
scanf("\n");
scanf("%c",&ans);
return ans;
}
 
P

Peter Nilsson

When I rename the variables d,p TO : do,po in all the module of :
void convert_meter(float *me,float *d,float *p)
I got an error of that line of : void convert_meter(float *me,float
*d,float *p)

What happens when you rename d to while?
What happens when you rename d to for?

Hint:
 
A

Ancient_Hacker

When I rename the variables d,p TO : do,po in all the module of :


C compilers are famous for parsing correct C programs, but not having a
clue what's wrong with a slightly incorrect one. Something to do with
yacc.


In case you havent caught on, "do" is a reserverd word in C.

You might also benefit from downloading a newer C compiler. Borland
gives away 5.5 IIRC, and Microsoft gives away VC8 2005 Express.
 
K

Keith Thompson

When I rename the variables d,p TO : do,po in all the module of :
void convert_meter(float *me,float *d,float *p)
I got an error of that line of : void convert_meter(float *me,float
*d,float *p)

E:\programs\c_lang\iti01\tc201\ch05\own>tcc pnt02o04
Turbo C Version 2.01 Copyright (c) 1987, 1988 Borland International
pnt02o04.c:
Error pnt02o04.c 44: Declaration syntax error
*** 1 errors in Compile ***

Available memory 396264

Others have already answered your question, but I have some comments
on your code.
#include "stdio.h"

void main()

main returns int. Change this to

int main(void)
{
float meter,dots,points;

Using float is ok, but in most cases double makes more sense. double
provides more range and precision than float, and it's typically not
much more expensive. The only good reason to use float rather than
double is to save space in large arrays, and then only if it's worth
the reduced precision. (If you use double rather than float, you'll
need to change the format strings for printf() and scanf().)
void input_meter();
void convert_meter();
char another();

The empty parentheses mean that the functions take an unspecified (but
fixed) number and type of arguments. There's no reason not tell the
compiler exactly what these functions expect:

void input_meter(float *me);
void convert_meter(float *me,float *d,float *p);
char another(void);

[snip]
void input_meter(float *me)
{
printf("\nEnter size in meter : ");
scanf("%f",me);
}

This might be cleaner as a function returning float (or double).
void convert_meter(float *me,float *d,float *p)
{
*d=((*me)*300)/(0.0254);
*p=((*me)*720)/(0.0254);
printf("\n %f Meter is = %f dots %f points",*me,*d,*p);
}

Why is the first argument a pointer? You can just pass the
floating-point value directly.

[snip]

Finally, indentation is your friend. If you indented the code using
tab characters, they may have been lost when you posted it. If you
didn't indent it at all, you really should.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top