Sponsored Content
Top Forums UNIX for Advanced & Expert Users Help please...output problems with printf. Post 302248756 by pwanda on Sunday 19th of October 2008 02:51:23 PM
Old 10-19-2008
Error Help please...output problems with printf.

Code:
#include <stdio.h>
#include <math.h>

// this function calculates the volume of a Cylinder
int main(void)
{
    int r;    // radius
    int h;    // height
    double M_PI; // pi
    
    int pOne = pow (r, 2);  
    
    // get user input of radius and height
    printf ("Enter your radius: ");
    scanf ("%f", &r);
    printf ("Enter your height: ");
    scanf ("%f", &h);

    // calculate volume
    
    volumeCylinder = pOne * M_PI * h;

    // output volume result
    
    printf ("The Volume of the Cylinder is: %lf\n", volumeCylinder);

    return 0;

}

Sample Output:
Code:
~Enter your radius: 3
~Enter your height: 2
~The Volume of the Cylinder is: 0.000000
~

The program compiles and runs but no matter what kind of printf format I do (double, float, int) I always get 0.0000..., -0.000..., or some really large number.

I don't know what could be wrong. Can anybody please help me with this? It is driving me insane.
 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find: problems escaping printf-command string

Hi Folks! Can you help me with this find -printf command. I seem to be unable to execute the printf-command from my shell script. I'm confused: :confused: My shell script snippet looks like this: #!/bin/sh .. COMMAND="find ./* -printf '%p %m %s %u %g \n'" echo "Command: ${COMMAND}"... (1 Reply)
Discussion started by: grahamb
1 Replies

2. Shell Programming and Scripting

How to format the output using float in awk{printf}

Hi I'm using awk to manipulate the data in the 6th field of the file xxx_yyy.hrv. The sample data that is available in this field is given below 220731.7100000000000000 When i tried using this command cat xxx_yyy.hrv | awk '{printf("%23.16f\n",$6*-1)}' I get the output as... (4 Replies)
Discussion started by: angelarosh
4 Replies

3. Programming

capture the output of printf into another variable

Hi , I wonder if in java I can pipe the below output of the printf into a variable: System.out.printf(" This is a test %s\n", myVariable); I want to keep the output of the printf command to create my history array. Thanks. (2 Replies)
Discussion started by: arizah
2 Replies

4. Shell Programming and Scripting

printf Hexadecimal output

printf "%X\n" "A" 41 printf "%X\n" "2" 2 Expected 32 (not 2). Is there a "printf" which will output the hexadecimal value of a numeric character? (9 Replies)
Discussion started by: methyl
9 Replies

5. Shell Programming and Scripting

Problems with awk printf, formatted output

Hi, i have a script, which is incomplete, am on my way developing it. Input 1,12,2012,IF_TB001 2,12,2012,3K3 3,Z56,00000,25,229,K900,00, ,3G3, ,USD, ,0000000000,000, , , , 550000000 3,Z56,00000,53,411,W225,00,000, , ,USD,OM170,0000000000,000, , , , -550000000 4,Z56,COUNT, 4,SUM LOC,... (19 Replies)
Discussion started by: selvankj
19 Replies

6. Shell Programming and Scripting

Excel table like output with printf

Hi All; I try to create a excel like table with headers and some fields containing values, other long and complex mathematic formulas. I have some header like : Name Formula Value True/False Under name column, they are some formula names, formula column some long mathematic formulas... (9 Replies)
Discussion started by: reseki
9 Replies

7. Shell Programming and Scripting

Managing output... echo or printf?

Hello script guru's as i write more and more code i always block at managing output... either writing to standard out, writing to files via std out (log, temp file, etc). Don't get me wrong 99% of the time it DOES the job but maybe there is more efficient. I'm writing a small script to... (2 Replies)
Discussion started by: maverick72
2 Replies

8. UNIX for Beginners Questions & Answers

How to use printf to output a shell variable path?

So I created two shell variables: COLUMN1_HEADING, COLUMN2_HEADING. They have values: COLUMN1_HEADING="John" COLUMN2_HEADING="123456789" How would I use printf to get it to print an output like this: $COLUMN1_HEADING\t$COLUMN2_HEADING\nJohn\t123456789\n Thanks! (3 Replies)
Discussion started by: steezuschrist96
3 Replies
GMAGICK(3)								 1								GMAGICK(3)

The Gmagick class

INTRODUCTION
CLASS SYNOPSIS
Gmagick Gmagick Methods o public Gmagick Gmagick::addimage (Gmagick $Gmagick) o public Gmagick Gmagick::addnoiseimage (int $NOISE) o public Gmagick Gmagick::annotateimage (GmagickDraw $GmagickDraw, float $x, float $y, float $angle, string $text) o public Gmagick Gmagick::blurimage (float $radius, float $sigma, [int $channel]) o public Gmagick Gmagick::borderimage (GmagickPixel $color, int $width, int $height) o public Gmagick Gmagick::charcoalimage (float $radius, float $sigma) o public Gmagick Gmagick::chopimage (int $width, int $height, int $x, int $y) o public Gmagick Gmagick::clear (void ) o public Gmagick Gmagick::commentimage (string $comment) o public Gmagick Gmagick::compositeimage (Gmagick $source, int $COMPOSE, int $x, int $y) o public Gmagick::__construct ([string $filename]) o public Gmagick Gmagick::cropimage (int $width, int $height, int $x, int $y) o public Gmagick Gmagick::cropthumbnailimage (int $width, int $height) o public Gmagick Gmagick::current (void ) o public Gmagick Gmagick::cyclecolormapimage (int $displace) o public void Gmagick::deconstructimages (void ) o public Gmagick Gmagick::despeckleimage (void ) o public Gmagick Gmagick::destroy (void ) o public Gmagick Gmagick::drawimage (GmagickDraw $GmagickDraw) o public Gmagick Gmagick::edgeimage (float $radius) o public Gmagick Gmagick::embossimage (float $radius, float $sigma) o public Gmagick Gmagick::enhanceimage (void ) o public Gmagick Gmagick::equalizeimage (void ) o public Gmagick Gmagick::flipimage (void ) o public Gmagick Gmagick::flopimage (void ) o public Gmagick Gmagick::frameimage (GmagickPixel $color, int $width, int $height, int $inner_bevel, int $outer_bevel) o public Gmagick Gmagick::gammaimage (float $gamma) o public string Gmagick::getcopyright (void ) o public string Gmagick::getfilename (void ) o public void Gmagick::getimagebackgroundcolor (void ) o public array Gmagick::getimageblueprimary (void ) o public void Gmagick::getimagebordercolor (void ) o public int Gmagick::getimagechanneldepth (int $channel_type) o public int Gmagick::getimagecolors (void ) o public int Gmagick::getimagecolorspace (void ) o public int Gmagick::getimagecompose (void ) o public int Gmagick::getimagedelay (void ) o public int Gmagick::getimagedepth (void ) o public int Gmagick::getimagedispose (void ) o public array Gmagick::getimageextrema (void ) o public string Gmagick::getimagefilename (void ) o public string Gmagick::getimageformat (void ) o public float Gmagick::getimagegamma (void ) o public array Gmagick::getimagegreenprimary (void ) o public int Gmagick::getimageheight (void ) o public array Gmagick::getimagehistogram (void ) o public int Gmagick::getimageindex (void ) o public int Gmagick::getimageinterlacescheme (void ) o public int Gmagick::getimageiterations (void ) o public int Gmagick::getimagematte (void ) o public void Gmagick::getimagemattecolor (void ) o public string Gmagick::getimageprofile (string $name) o public array Gmagick::getimageredprimary (void ) o public int Gmagick::getimagerenderingintent (void ) o public array Gmagick::getimageresolution (void ) o public int Gmagick::getimagescene (void ) o public string Gmagick::getimagesignature (void ) o public int Gmagick::getimagetype (void ) o public int Gmagick::getimageunits (void ) o public array Gmagick::getimagewhitepoint (void ) o public int Gmagick::getimagewidth (void ) o public string Gmagick::getpackagename (void ) o public array Gmagick::getquantumdepth (void ) o public string Gmagick::getreleasedate (void ) o public array Gmagick::getsamplingfactors (void ) o public array Gmagick::getsize (void ) o public array Gmagick::getversion (void ) o public mixed Gmagick::hasnextimage (void ) o public mixed Gmagick::haspreviousimage (void ) o public mixed Gmagick::implodeimage (float $radius) o public mixed Gmagick::labelimage (string $label) o public mixed Gmagick::levelimage (float $blackPoint, float $gamma, float $whitePoint, [int $channel = Gmagick::CHANNEL_DEFAULT]) o public mixed Gmagick::magnifyimage (void ) o public Gmagick Gmagick::mapimage (gmagick $gmagick, bool $dither) o public void Gmagick::medianfilterimage (float $radius) o public void Gmagick::minifyimage (void ) o public void Gmagick::modulateimage (float $brightness, float $saturation, float $hue) o public void Gmagick::motionblurimage (float $radius, float $sigma, float $angle) o public void Gmagick::newimage (int $width, int $height, string $background, [string $format]) o public bool Gmagick::nextimage (void ) o public void Gmagick::normalizeimage ([int $channel]) o public void Gmagick::oilpaintimage (float $radius) o public bool Gmagick::previousimage (void ) o public void Gmagick::profileimage (string $name, string $profile) o public void Gmagick::quantizeimage (int $numColors, int $colorspace, int $treeDepth, bool $dither, bool $measureError) o public void Gmagick::quantizeimages (int $numColors, int $colorspace, int $treeDepth, bool $dither, bool $measureError) o public array Gmagick::queryfontmetrics (GmagickDraw $draw, string $text) o public array Gmagick::queryfonts ([string $pattern = "*"]) o public array Gmagick::queryformats ([string $pattern = "*"]) o public void Gmagick::radialblurimage (float $angle, [int $channel = Gmagick::CHANNEL_DEFAULT]) o public void Gmagick::raiseimage (int $width, int $height, int $x, int $y, bool $raise) o public void Gmagick::read (string $filename) o public void Gmagick::readimage (string $filename) o public void Gmagick::readimageblob (string $imageContents, [string $filename]) o public void Gmagick::readimagefile (resource $fp, [string $filename]) o public void Gmagick::reducenoiseimage (float $radius) o public void Gmagick::removeimage (void ) o public string Gmagick::removeimageprofile (string $name) o public void Gmagick::resampleimage (float $xResolution, float $yResolution, int $filter, float $blur) o public void Gmagick::resizeimage (int $width, int $height, int $filter, float $blur, [bool $fit = false]) o public void Gmagick::rollimage (int $x, int $y) o public Gmagick Gmagick::rotateimage (mixed $color, float $degrees) o public Gmagick Gmagick::scaleimage (int $width, int $height, [bool $fit = false]) o public Gmagick Gmagick::separateimagechannel (int $channel) o public Gmagick Gmagick::setfilename (string $filename) o public Gmagick Gmagick::setimagebackgroundcolor (GmagickPixel $color) o public Gmagick Gmagick::setimageblueprimary (float $x, float $y) o public Gmagick Gmagick::setimagebordercolor (GmagickPixel $color) o public Gmagick Gmagick::setimagechanneldepth (int $channel, int $depth) o public Gmagick Gmagick::setimagecolorspace (int $colorspace) o public Gmagick Gmagick::setimagecompose (int $composite) o public Gmagick Gmagick::setimagedelay (int $delay) o public Gmagick Gmagick::setimagedepth (int $depth) o public Gmagick Gmagick::setimagedispose (int $disposeType) o public Gmagick Gmagick::setimagefilename (string $filename) o public Gmagick Gmagick::setimageformat (string $imageFormat) o public Gmagick Gmagick::setimagegamma (float $gamma) o public Gmagick Gmagick::setimagegreenprimary (float $x, float $y) o public Gmagick Gmagick::setimageindex (int $index) o public Gmagick Gmagick::setimageinterlacescheme (int $interlace) o public Gmagick Gmagick::setimageiterations (int $iterations) o public Gmagick Gmagick::setimageprofile (string $name, string $profile) o public Gmagick Gmagick::setimageredprimary (float $x, float $y) o public Gmagick Gmagick::setimagerenderingintent (int $rendering_intent) o public Gmagick Gmagick::setimageresolution (float $xResolution, float $yResolution) o public Gmagick Gmagick::setimagescene (int $scene) o public Gmagick Gmagick::setimagetype (int $imgType) o public Gmagick Gmagick::setimageunits (int $resolution) o public Gmagick Gmagick::setimagewhitepoint (float $x, float $y) o public Gmagick Gmagick::setsamplingfactors (array $factors) o public Gmagick Gmagick::setsize (int $columns, int $rows) o public Gmagick Gmagick::shearimage (mixed $color, float $xShear, float $yShear) o public Gmagick Gmagick::solarizeimage (int $threshold) o public Gmagick Gmagick::spreadimage (float $radius) o public Gmagick Gmagick::stripimage (void ) o public Gmagick Gmagick::swirlimage (float $degrees) o public Gmagick Gmagick::thumbnailimage (int $width, int $height, [bool $fit = false]) o public Gmagick Gmagick::trimimage (float $fuzz) o public void Gmagick::write (string $filename) o public Gmagick Gmagick::writeimage (string $filename, [bool $all_frames = false]) PHP Documentation Group GMAGICK(3)
All times are GMT -4. The time now is 05:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy