Oki, ça va etre un peu long, mais voila le code :
fancontrol.h :
/*---------------------------------------------------------------------*
* fancontrol.h Osmalskyj Julien 2007-10-03
*
* Interface for fancontrol.c
*---------------------------------------------------------------------*/
#include <stddef.h>
#define SENSORS 17
typedef struct Thm_t Thermal;
/***********************************************************************
* int getThm(FILE* file_in) : get temperatures from the file pointed *
* by char* file_in. *
**********************************************************************/
int getThm(FILE* file_in, struct Thm_t* fandata);
fancontrol.c :
/*-------------------------------------------------------------------------*
* fancontrol.c Osmalskyj Julien 2007-10-26
*
* Implementations for functions and routines declared in file
* fancontrol.h
*-------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <errno.h>
#include "fancontrol.h"
//Thermal sensors structure
struct Thm_t {
int temp_vect[SENSORS]; // temperatures vector
int cycle; // cycle for temperatures check
bool active; // modify fan or just monitor temperatures
int fan_off; // 0x2F
int fan_low_speed; // 0x02
int fan_medium_speed; // 0x04
int fan_max_speed; // 0x07
int fan_bios_control; // 0x80
};
//getThm function
int getThm(FILE* file_in, struct Thm_t* fandata) {
if (file_in == NULL) { // error opening file
fprintf(stderr, "error: unable to open thermals file.");
return 1;
}
char* getInput;
char getLine[100] = "";
getInput = fgets(getLine, 100, file_in);
if (getInput == NULL) {
return 1;
}
char* nptr = getLine;
char* endptr = nptr;
int sensorNB = 0; // sensor number
while (*endptr != '\0') {
while (*nptr == ' ') // skip white spaces
nptr++;
errno = 0;
int result = (int)strtod(nptr, &endptr);
if (result == 0) { // Skip if not conversible value
nptr++;
}
else {
fandata->temp_vect[sensorNB] = result; //SIGSEV HERE
sensorNB++;
if (errno == ERANGE)
printf("Warning: Overflow or underflow on next value\n");
if (nptr == endptr)
nptr++;
else if (nptr != endptr)
nptr = endptr;
}
}
int i = 0;
//Prints temperatures on screen
printf("Temperatures : ");
while (i < 17) {
printf("%d ", fandata->temp_vect[i]);
i++;
}
printf("\n");
return 0;
}
enfin main.c :
/*---------------------------------------------------------------------------*
* main.c Osmalskyj Julien 2007-26-03
*
* Linux TP-Fancontrol : fan control program for IBM / Lenovo Thinkpad
* laptop computers. This program sets fan speed according to temperatures
* defined in a config file.
*---------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <getopt.h>
#include <time.h>
#include <errno.h>
#include "fancontrol.h"
int main(int argc, char* argv[]) {
FILE* open = fopen("/proc/acpi/ibm/thermal", "r");
if (open == NULL) {
fprintf(stderr, "error loading thermal file\n");
return 1;
}
//Thermal* test_struct;
struct Thm_t test_struct = malloc(sizeof(struct Thm_t));
getThm(open, test_struct);
fclose(open);
return 0;
}
C'est bien sympa de votre part merci les gars

Edité par Amwus ( 26/10/2007 21:48:01 )"Engl Amps are the best i've ever used... Not only are they powerfull, but they have charachter too..." R. Blackmore