1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
| double getDefine(char* label)
{
FILE *file;
char c;
char word[25];
char value[5];
int i,j;
bool found=false;
/* open */
file = fopen(FIC_INIT, "r");
if(file == NULL){
fprintf(stdout, "Impossible d'ouvrir le fichier %s\n", FIC_INIT);
return -1;
}
word[0]='\0';
value[0]='\0';
i=0;
c = fgetc (file);
do {
if (c=='#')
{
while(c!='\n')
{
c=fgetc(file);
}
}
else if (c=='\n')
{
while(c=='\n')
{
c=fgetc(file);
}
}
else if (c==' ')
{
while(c==' ')
{
c=fgetc(file);
}
}
else if (c == '=')
{
word[i]='\0';
fprintf(stdout, "oh '%s'\n", word);
fprintf(stdout, "%d\n", strcmp(label,word));
if(strcmp(label,word)==0)
{
j=0;
while(c!='\n')
{
c=fgetc(file);
while(c==' ')
{
c=fgetc(file);
}
value[j]=c;
j++;
}
value[j]='\0';
fprintf(stdout, "%s et %f\n", word, atof(value));
found=true;
}
else
{
word[0]='\0';
value[0]='\0';
while(c!='\n')
{
c=fgetc(file);
}
i=0;
}
}
else
{
word[i]=c;
i++;
c=fgetc(file);
}
} while (c != EOF && found==false);
/* close */
if(fclose(file) == EOF) {
fprintf(stdout,"Probleme de fermeture du fichier %s", FIC_INIT);
return -1;
}
if (found==false)
{
return -1;
}
return atof(value);
}
} |
Partager