base-exponent (c program)
Tue Nov 18 2008, 03:09 am
i am writing program that calculate the power value. this program below giving me errors.
can some one help me please?
can some one help me please?
#include "C:\egnu110\include\hcs12.h" #include "C:\egnu110\include\delay2.c" #include "c:\egnu110\include\stdio.c" const char *msg = "Enter a decimal number\n"; const char *msg1 = "Enter a power of decimal number\n"; const char *msg2 = "The Value is = "; int calcpower(int base,int expo); int main(void) { int base=0,expo=0; puts (msg); base = getch(); puts (msg1); expo = getch(); return 0; } calcpower(int base, int expo) { int i=0, val=1, buf[4]; while(i<expo){ val=val*base; i++ ; newline(); newline(); int2alpha(val,buf); puts(msg2); puts(val); putsr(&buf[0]); } }
[ Edited Tue Nov 18 2008, 12:05 pm ]
Tue Nov 18 2008, 08:20 pm
i am getting two errors.
1.passing arg 1 of `puts' makes pointer from integer without a cast
2.passing arg 1 of `putsr' from incompatible pointer type
1.passing arg 1 of `puts' makes pointer from integer without a cast
2.passing arg 1 of `putsr' from incompatible pointer type
Fri Nov 21 2008, 08:31 am
anyone can tell me what is wrong with my program please?aj1
Oh alright
>1.passing arg 1 of `puts' makes pointer from integer without a cast
>puts(val);
puts expects to be given a message to print, and val is an integer (a number)
You have to convert val to a string (text) before you can print it.
A lot depends on the flexibility of your compiler, but you have defined buf as a string
of integers and putsr probably expects a string of chars
try
char buf[20];
then
putsr(buf);
putsr(buf[0])
putsr(&buf[0]);
then ask again
[ Edited Fri Nov 21 2008, 08:43 am ]
Powered by e107 Forum System