473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

pow type problem

Is this one of those rare instances where casts are needed? I have this
code and the compiler complains that the prototypes are wrong.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int
main (int argc, char *argv[])
{
if (argc != 4)
{
puts ("usage error");
exit(EXIT_FAILURE);
}
double x, y;
x = strtod (argv[1], NULL);
y = strtod (argv[2], NULL);
printf ("%.2f\n", pow (argv[1], argv[2]));
return 0;
}

And I did try to link with libm.a

Bill
Jun 27 '08 #1
6 1337
Ok I see now. Sorry false alarm. I see a couple of errors in the code.
D?mn. The pow needs xand y Sorry again.

Bill
Jun 27 '08 #2
In article <z3J_j.3440$tF1.560@trnddc01>,
Bill Cunningham <no****@nspam.comwrote:
Is this one of those rare instances where casts are needed? I have this
code and the compiler complains that the prototypes are wrong.
>#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int
main (int argc, char *argv[])
{
if (argc != 4)
{
puts ("usage error");
exit(EXIT_FAILURE);
}
double x, y;
x = strtod (argv[1], NULL);
y = strtod (argv[2], NULL);
printf ("%.2f\n", pow (argv[1], argv[2]));
It would seem to me to make more sense to use

printf ("%.2f\n", pow (x, y));
return 0;
}
And I did try to link with libm.a

Question: what are you expecting in argv[3] ? You exit the program
if argc != 4 but you do not make use of the 4th argument, just
the 2nd and 3rd (it being quite understandable why you aren't making
use of the 1st argument.)
--
"Whenever there is a hard job to be done I assign it to a lazy
man; he is sure to find an easy way of doing it."
-- Walter Chrysler
Jun 27 '08 #3
"Bill Cunningham" <no****@nspam.comwrites:
Is this one of those rare instances where casts are needed? I have this
code and the compiler complains that the prototypes are wrong.
No, no casts are needed.

Presumably your compiler is complaining that the call is wrong, not
that the prototype is wrong.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int
main (int argc, char *argv[])
{
if (argc != 4)
{
puts ("usage error");
exit(EXIT_FAILURE);
}
You use only the first two arguments. Why do you want argc to be 4
rather than 3?
double x, y;
x = strtod (argv[1], NULL);
y = strtod (argv[2], NULL);
printf ("%.2f\n", pow (argv[1], argv[2]));
argv[1] and argv[2] are of type char*. pow expects two arguments of
type double.

You've just declared and assigned values to two objects x and y of
type double, but you never use them.

Think about it.
return 0;
}

And I did try to link with libm.a
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #4

"Walter Roberson" <ro******@ibd.nrc-cnrc.gc.cawrote in message
news:g1**********@canopus.cc.umanitoba.ca...
Question: what are you expecting in argv[3] ? You exit the program
if argc != 4 but you do not make use of the 4th argument, just
the 2nd and 3rd (it being quite understandable why you aren't making
use of the 1st argument.)
4 was one of the bugs. I didn't see it until after I posted. Sorry.

Bill
Jun 27 '08 #5

"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
argv[1] and argv[2] are of type char*. pow expects two arguments of
type double.

You've just declared and assigned values to two objects x and y of
type double, but you never use them.

Think about it.
> return 0;
}

And I did try to link with libm.a
Thanks.

Bill
Jun 27 '08 #6
On 27 May, 02:01, "Bill Cunningham" <nos...@nspam.comwrote:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int
main (int argc, char *argv[])
{
* if (argc != 4)
* * {
* * * puts ("usage error");
* * * exit(EXIT_FAILURE);
* * }
* double x, y;
you can't mix statements and declarations in C90.
For C90 compilance put the double x, y;
before the if

* x = strtod (argv[1], NULL);
* y = strtod (argv[2], NULL);
* printf ("%.2f\n", pow (argv[1], argv[2]));
* return 0;

}

--
Nick Keighley

Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Sean Ross | last post by:
Hi. Recently I made a small script to do some file transferring (among other things). I wanted to monitor the progress of the file transfer, so I needed to know the size of the files I was...
1
by: Geoff Biggs | last post by:
Evening all, I'm trying to add a new built-in number data type to Python with its own syntax, so I'm working directly with the interpreter rather than creating my own extension module (side...
4
by: wkaras | last post by:
I would like to propose the following changes to the C++ Standard, the goal of which are to provide an improved ability to specify the constraints on type parameters to templates. Let me say from...
0
by: Nashat Wanly | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaskdr/html/askgui06032003.asp Don't Lock Type Objects! Why Lock(typeof(ClassName)) or SyncLock GetType(ClassName) Is Bad Rico...
7
by: | last post by:
Source Error: Line 173: sData(rownumber - 1, lcnt) = WhatCol.Value Line 174: End IF Line 175: If (sData(rownumber, lcnt) = sData(rownumber - 1, lcnt)) AND...
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
12
by: Joel Byrd | last post by:
I'm having a little problem with using type-ahead functionality for an auto-suggest box. Sometimes, when I start to type something and the type-ahead shows up, the AJAX will send a request query...
7
by: Sky | last post by:
I have been looking for a more powerful version of GetType(string) that will find the Type no matter what, and will work even if only supplied "{TypeName}", not the full "{TypeName},{AssemblyName}"...
0
by: StephQ | last post by:
I face two problems related to template classes. The first one is that you can not have the parameters of a class automatically deduced by the constructor. You can solve this problem using...
1
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= | last post by:
I get the above error in some of the ASP.NET web applications on a server, and I need some help figuring out how to deal with it. This is a rather long post, and I hope I have enough details that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.