/*Output Section */
printf ("\nThat height is equivalent to " "%1f" " feet and " "%2f" " inch(es).\n");
scanf ("%f", &FEET);
scanf ("%f", &INCHES);

Dani AI

Generated

correctly pointed out the immediate problem: the format string in 's printf contains conversion specifiers but no matching arguments. In C adjacent string literals are concatenated at compile time, so the final format passed to printf still has %f specifiers even though no values were supplied. A missing argument for a conversion specifier is undefined behavior; compilers typically warn with "too few arguments for format" and the program can print garbage or crash at runtime.

A few technical clarifications that expand on 's formatting note: printf is a variadic function and relies on the caller to provide the exact number and types of arguments; there is no runtime type checking. Float values passed to printf are promoted to double, so "%f" expects a double; scanf, however, expects pointers: "%f" requires a float and "%lf" requires a double. Also remember the difference between width and precision: "%1f" sets a minimum field width, while "%.1f" sets one digit after the decimal. Literal quotes in output must be included literally or escaped inside the format string, as showed.

Practical checks to resolve "missing argument" issues: enable strict compiler warnings (for example, gcc -std=c11 -Wall -Wextra -Wformat=2 -pedantic) and fix every format warning; verify that the number and types of arguments match the conversion specifiers; confirm the variables used are declared with the correct types and that addresses are passed to scanf; check scanf's return value to ensure conversions succeeded; consider reading lines with fgets and converting with strtof for robust input handling. Treat any format warnings as errors to avoid undefined behavior.

Recommended Answers

All 2 Replies

The printf() statement contains %s and %f, but there are no arguments for them

char message[] = "Hello World";
printf("%s\n", message);

In the above, mssage is passed as an argument to printf(). Your printf() needs similar arguments.

/*Output Section */
printf ("\nThat height is equivalent to " "%1f" " feet and " "%2f" " inch(es).\n");
scanf ("%f", &FEET);
scanf ("%f", &INCHES);

This is how you add quotes to the specifiers and those are the correct parameters if you want to control the output of the floats.

printf ("\nThat height is equivalent to \"%.2f\" feet and \"%.2f\" inch(es).\n", feet, inches);
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.