#include "stm32l475e_iot01.h"
#include "stm32l475e_iot01_tsensor.h"
#include <math.h>
float temp_value = 0; // Measured temperature value
char str_tmp[100] = ""; // Formatted message to display the temperature value
int main (void)
{
HAL_UART_Transmit(&huart1,msg1,sizeof (msg1),1000);
HAL_UART_Transmit(&huart1,msg2,sizeof (msg2),1000);
BSP_TSENSOR_Init();
HAL_UART_Transmit(&huart1,msg3,sizeof (msg3),1000);
while (1) {
temp_value = BSP_TSENSOR_ReadTemp();
int tmpInt1 = temp_value;
float tmpFrac = temp_value - tmpInt1;
int tmpInt2 = trunc(tmpFrac * 100);
snprintf(str_tmp,100," TEMPERATURE = %d.%02d\n\r", tmpInt1, tmpInt2);
HAL_UART_Transmit(&huart1,( uint8_t* )str_tmp,sizeof (str_tmp),1000);
HAL_Delay(5000);
}
}

- 2,705
- 5
- 23
- 60

- 3
- 3
-
4`#include
` – kaylum Sep 24 '21 at 06:26 -
2Which if you type `man snprintf` at the command line on Linux (or open a browser and search `"man7 snprintf"`) the manual page will tell you what headers are needed. (the `"man7"` in the search will ensure you get the pages from [Linux man pages online - man7.org](https://man7.org/linux/man-pages/index.html)) – David C. Rankin Sep 24 '21 at 06:27
-
2Aside: `float temp_value` and `char str_tmp[100]` are either a poor choice of name, or a poor decision to make them global. – Weather Vane Sep 24 '21 at 06:30
-
Please trim your code to make it easier to find your problem. Follow these guidelines to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Community Sep 25 '21 at 17:23
1 Answers
"Implicit declaration" of anything usually means that you forgot an include. In this case you forgot "stdio".
#include <stdio.h>
In some cases, you may include one header file which includes a header file you need, and you can forget an include and get away with it.
Don't count on this.
Any reasonably well-written header file will have guards to ensure the preprocessor does not include it twice.
#ifndef MY_WHACKY_HEADER_H
#define MY_WHACKY_HEADER_H
// Something whacky
#endif
This means that you can include that header file anywhere you use its contents and if it's redundant, no harm done.
When in doubt about which header includes are necessary, if you have access to a Unix-y console, you can look up the manpage. For instance, to find out about snprintf
:
man snprintf
Alternatively, you can check cppreference.com. The documentation on functions there will include the header file they're declared in.

- 26,361
- 5
- 21
- 42
-
Please describe how to find out which header needs to be included for a used function. You can refer to Davids comment or describe the more modern other way. – Yunnosch Sep 24 '21 at 07:46
-
If you have a Unix-y command line environment at hand, you can run `man snprintf` or you can do a search online for the same and find the manpage for functions. You can also check out [cppreference.com](https://en.cppreference.com/w/c/io) which is very helpful and lists the required include. – Chris Sep 24 '21 at 14:59
-