diff --git a/main.c b/main.c index e1988a369b99a87fc0654a7addb32e4050533e5c..6d879eb5715f36f6ecb0eadcffb2eb51b2df3130 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,27 @@ #include <stdio.h> +#include <stdlib.h> + +void read_cpu_temp() { + FILE *file; + char buffer[1024]; + char *temp_path = "/sys/class/thermal/thermal_zone0/temp"; + + file = fopen(temp_path, "r"); + if (file == NULL) { + printf("Error opening file\n"); + return; + } + + if (fgets(buffer, sizeof(buffer), file) != NULL) { + long temp = atol(buffer) / 1000; + printf("CPU temperature: %ld C\n", temp); + } else { + printf("Error reading file\n"); + } + fclose(file); +} int main(void) { - printf("Hello, World!\n"); + read_cpu_temp(); return 0; } \ No newline at end of file