Δημοσιεύτηκε: 06 Οκτ 2011, 17:05
από migf1
Πάντως με αυτό εδώ το myfile.txt...

Κώδικας: Επιλογή όλων

athens 12/1/2011 26 46 n
patras 12/1/2011 28 56 s
salonica 12/1/2011 24 35 n
heraklion 12/1/2011 30 60 n


μου βγάζει αυτό το αποτέλεσμα (που δείχνει να είναι ΟΚ)...

Κώδικας: Επιλογή όλων

--- > 12
--- > 1
--- > 2011
### pch: 2011 and atoi-pch: 2011
--- > 12
--- > 1
--- > 2011
### pch: 2011 and atoi-pch: 2011
--- > 12
--- > 1
--- > 2011
### pch: 2011 and atoi-pch: 2011
--- > 12
--- > 1
--- > 2011
### pch: 2011 and atoi-pch: 2011

0-0: 12 | 0-1: 1 | 0-2: 12 |
1-0: 12 | 1-1: 1 | 1-2: 12 |
2-0: 12 | 2-1: 1 | 2-2: 12 |
3-0: 12 | 3-1: 1 | 3-2: 2011 |
4-0: 2011 | 4-1: 0 | 4-2: 0 |
5-0: 0 | 5-1: 3296720 | 5-2: 0 |
6-0: 0 | 6-1: 3299739 | 6-2: 0 |
7-0: 0 | 7-1: 0 | 7-2: 0 |
8-0: 0 | 8-1: 0 | 8-2: 0 |
9-0: 0 | 9-1: 1073751289 | 9-2: 1 |
10-0: 1 | 10-1: 3 | 10-2: 0 |
11-0: 0 | 11-1: 2958 | 11-2: 0 |
12-0: 0 | 12-1: 0 | 12-2: 0 |
13-0: 0 | 13-1: 3281696 | 13-2: 0 |
14-0: 0 | 14-1: 3299739 | 14-2: 0 |
15-0: 0 | 15-1: 3299739 | 15-2: 0 |
16-0: 0 | 16-1: 0 | 16-2: 0 |
17-0: 0 | 17-1: -51086256 | 17-2: 2046 |
18-0: 2046 | 18-1: 3296720 | 18-2: 0 |
19-0: 0 | 19-1: 3296720 | 19-2: 0 |
20-0: 0 | 20-1: 6040 | 20-2: 1634887016 | teleiwwse kanonika!!!


Απλώς αραίωσα τον κώδικά σου για να μπορέσω να τον διαβάσω, δεν του άλλαξα κάτι (btw, γιατί ρε παιδιά γράφετε τόσο συμπυκνωμένο τον κώδικα; )

Κώδικας: Επιλογή όλων

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// -----------------------------------------------------------------------------------
int main( void )
{
FILE *infile;
char city[32]; // ...gia tin poly
char date[16]; // ...gia tin imerominia
int temp; // ...gia tin thermokrasia
int humi; // ...gia tin ygrasia
char wind[4]; // ...gia ton anemo
int j=0, i=0;
int D[21][2];

infile = fopen("myfile.txt", "r");
if ( infile == NULL )
{
printf("Error code 1: File does not exist!\n");
exit( 1 );
}

while ( fscanf(infile, "%s %s %d %d %s", city, date, &temp, &humi, wind) != EOF )
{
char *pch;
j = 0;
pch = strtok( date, "/" );
while ( pch != NULL )
{
printf("--- > %s\n", pch);

if (j == 0) {
D[i][0] = atoi( pch );
}
else if (j == 1) {
D[i][1] = atoi( pch );
}
else if (j == 2) {
printf("### pch: %s and atoi-pch: %d \n", pch, atoi( pch ) );
D[i][2] = atoi( pch );
}

pch = strtok( NULL, "/" );
j++;
}

/*
printf("city: %s\n", city);
printf("date: %s\n", date);
printf("temp: %d\n", temp);
printf("humi: %d\n", humi);
printf("wind: %s\n\n", wind);
*/

i++;
}

for (i=0; i < 21; i++)
{
printf("\n");
for (j=0; j < 3; j++)
printf("%d-%d: %d |\t", i, j, D[i][j]);
}

printf("teleiwwse kanonika!!! \n");

return 0;
}