[SOLVED] .c error when compiling: %lf expects double but 2nd is char.
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
.c error when compiling: %lf expects double but 2nd is char.
this is total bunk as i have zero char set. i only set double as that is all im using:
Code:
//The formula V=1/3lwh gives the volume (V) of a rectangular
//pyramid with length (l), width (w) and height (h)
//##########################################################
// Created by Raymond L. Brunkow
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 or version 3 of the
// license, at your option.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//##########################################################
#include<stdio.h>
//Problem Input
// double for l, w, h in meters
//Problem Output
// double in cubic meters
// Formula: V=1/3*(l*w*h) or V=(double)1/(double)3*(l*w*h*) or V=(l*w*h*)/(double)3
int main(void)
{
// setting variables
double l, w, h, v;
//get inputs for length, width, and height in meters.
printf("\nPlease enter the (l)ength, (w)idth, and (h)eight in meters: \n");
scanf("%lf", "%lf", "%lf", &l, &w, &h);
//Formula for Volume of rectangular pyramid
v = ( l * w * h ) / (double)3;
// output
printf("\nThe volume of your rectangular pyramid with %.2f (l)ength, %.2f (w)idth, and %.2f (h)eight in meters is %.2f cubic meters.\n", l, w, h, v);
sleep(5);
return(0);
}
absolutely zero char set as variables, only double. double requires %lf, so that is exactly what im using. what is gcc doing?
error:
Code:
ssma-imac:ENG-3211 ssma$ gcc -o VOL volume_rectangular_pyramid.c
volume_rectangular_pyramid.c: In function ‘main’:
volume_rectangular_pyramid.c:38: warning: writing into constant object (argument 2)
volume_rectangular_pyramid.c:38: warning: format ‘%lf’ expects type ‘double *’, but argument 2 has type ‘char *’
again i dont have a 'char *' type in my script.
no this is not homework, just practice. only homework this week is to read cpt 1-2, and 3.1/3.2 but i dont like going that long (3 weeks) without some kind of practice. im practicing the set type (double)3 in my equation line along with combining input/output on the same line of script.
That's not how you use scanf. The first argument to scanf is a string containing what you want to scan. You have split this string across the first 3 arguments. Also note that you are missing an include of unistd.h, where sleep() is declared.
That's not how you use scanf. The first argument to scanf is a string containing what you want to scan. You have split this string across the first 3 arguments. Also note that you are missing an include of unistd.h, where sleep() is declared.
ok im a bit confused, still very new to C, i was looking at an example the prof. gave last class with scanf:
Code:
double a, b, c, disc, root_1, root2;
foo
printf("Please enter a, b, and c: ");
scanf("%lf %lf %lf", &a, &b, &c);
i saw one error i made with "" around each %lf and ',' that didnt need to be there. still same error as before.
interesting, i have the sleep(n) in all of my scripts and have never had to use anything other then stdio.h
thank you. that did the trick. odd that with unistd.h not being in any of my other scripts that sleep(n) worked without a hitch. any idea's why that is?
Your version of gcc may be lenient by default and recognize the implied include of unistd.h. I've seen older versions error out. Either way, including it is the right thing to do.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.