(Linux)I am trying to use this code:
/*
*Converts pounds to kilograms.
*/
#include <studio.h> /* printf, scanf,definitions*/
#define KG_PER_POUND .4536 /*conversion constant */

int
main(void)
{
double pounds, /* input - weight in pounds. */
kg; /*output - weight in kilograms */

/* Get the weight in pounds. */
printf("Enter the weight in pounds> ");
scanf("%lf", &pounds);

/* Convert the weight to kilograms. */
kg = KG_PER_POUND * pounds;

/* Display the weight in kilograms. */
printf("That equals %f kilograms. \n", kg);

return (0);
}

And after I try to to run it in terminal using
pwd
ls
gcc -o lab1 lab1.c
I keep getting the message "lab1.c:4: fatal error: studio.h: No such file or directory
compilation terminated"
Is there anything specifically that I am doing wrong? Thanks for any help.

First use code tags.

#include <stdio.h> /* printf, scanf,definitions*/
#define KG_PER_POUND .4536 /*conversion constant */

int main(void)
{
double pounds, kg; 

/* Get the weight in pounds. */
printf("Enter the weight in pounds> ");
scanf("%lf", &pounds);

/* Convert the weight to kilograms. */
kg = KG_PER_POUND * pounds;

/* Display the weight in kilograms. */
printf("That equals %f kilograms. \n", kg);

return (0);
}

Edited 5 Years Ago by alexchen: n/a

int
main(void)
{

When I was working on *nix and using vi I used to write code like that too, because vi can easily find any function by seaching for "^main". That's especially useful in long programs. But that was many many years ago, and IDEs have become smarter :)

printf("Enter the weight in pounds> ");
scanf("%lf", &pounds);

Two notes here. First, there's no \n, so the implementation isn't obligated to print the prompt before waiting for input; use fflush(stdout) to make sure it works regardless. Second, check the return value of scanf() to make sure your zero is actually a zero.

return (0)

return doesn't require parens. They don't hurt anything, but I prefer to leave them off.

This article has been dead for over six months. Start a new discussion instead.