Well I think I have a problem with my code that doesn't parse the data correctly.. I changed in my code like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
void adaugaInfoApa(struct INFO* info, struct TIMP* timp)
{
..
...
char tmpApa[6] = {0};
for (char ln[MAX] = {0}; fscanf(file, "%5s", tmpApa) != EOF && fgets(ln, 999, file) != NULL; );
info->diferenta = diferentaIndex(tmpApa, temp);
fprintf(file, "%s | %s | %s | %s | %ld \n", temp, timp->zi, timp->luna, timp->an, info->diferenta);
...
..
}
|
then the result isn't the one expected...
My true goal here is to parse the
char tmpApa to this function:
1 2 3 4 5 6 7 8 9 10 11
|
int diferentaIndex(char index1[MAX], char index2[MAX])
{
long int rezultat;
long int x, y;
x = atoi(index1);
y = atoi(index2);
rezultat = y - x;
return rezultat;
|
But seems the
"x" which has to be the
char index1, which passing to the function
adaugaInfoApa(struct INFO* info, struct TIMP* timp) where it has to be
char tmpApa is
0. Parsing the data to the
int diferentaIndex(char index1[MAX], char index2[MAX]), has to do an operation which is
, but what I got after the first executing the code is this:
1 2
|
11898 | 01 | 09 | 2020 | 0
12000 | 01 | 10 | 2020 | 12000 <- the result has to be 102
|
Well..
12000 - 11898 will not be ever = 12000, that means the
char tmpApa was 0 at that moment and I don't know what is the real problem.
I tried your example in an fresh project and is working in all formats.. so I guess I'm having a problem with my other function which is not working properly..
atoi() function isn't suppose to convert the string argument I mean
char to an
int integer? Then I can do whatever oeration I want with the arguments, or not ???