Discussion in "Software" started by    aj1    Nov 18, 2008.
Tue Nov 18 2008, 03:09 am
#1
i am writing program that calculate the power value. this program below giving me errors.
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, 12:08 pm
#2
are you getting any errors...?
what is the o/p?
Tue Nov 18 2008, 08:20 pm
#3
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
Thu Nov 20 2008, 09:20 pm
#4
anyone can tell me what is wrong with my program please?
Fri Nov 21 2008, 08:31 am
#5


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 ]

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Darrellciz
Thu Apr 18 2024, 11:07 am
Charlessber
Thu Apr 18 2024, 09:29 am
BartonSem
Thu Apr 18 2024, 04:56 am
DonaldKnown
Thu Apr 18 2024, 12:24 am
utaletxcyw
Wed Apr 17 2024, 10:21 am
Anthonyvab
Wed Apr 17 2024, 08:48 am
RobertCix
Wed Apr 17 2024, 06:46 am
Astorne
Tue Apr 16 2024, 08:52 pm