(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.

Dani AI

Generated

Classic, easy-to-fix compiler error. As pointed out, the fatal message means the compiler could not find the header on the include line — a misspelling or wrong case is the usual culprit on Linux (file names are case-sensitive). Also check for stray characters from Windows line endings (CRLF) or an invisible BOM which can turn #include <stdio.h> into something the preprocessor cannot match.

Quick troubleshooting checklist:

  • Verify the include line is the standard system header and has no stray characters or quotes.
  • Confirm the system header exists (for example, ls /usr/include/stdio.h).
  • Compile with warnings enabled so other problems show up: gcc -Wall -Wextra -std=c11 -pedantic -o lab1 lab1.c and run the program with ./lab1.

Input and runtime robustness (builds on ): standard output is buffered, so a prompt without a newline may not appear before input is read — either end the prompt with \n or call fflush(stdout) after the prompt. Always validate numeric input instead of assuming success; a more robust pattern is to read a line with fgets and parse it with strtod, checking the end pointer to verify a real number was entered.

Style and minor improvements: was right to suggest proper code formatting for readability; ’s note about alternate layout is fine as a style choice. For slightly better accuracy use a more precise pound-to-kilogram constant (0.45359237). The return 0; form is conventional and gcc with -Wall will flag other little issues.

Recommended Answers

All 4 Replies

The library name is stdio.h not studio.h

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);
}
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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.