Skip to content
Snippets Groups Projects
Commit 116a2943 authored by Felix Moser's avatar Felix Moser
Browse files

reading cpu temperature

parent 3638c67c
Branches
No related tags found
No related merge requests found
#include <stdio.h> #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) { int main(void) {
printf("Hello, World!\n"); read_cpu_temp();
return 0; return 0;
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment