怪!怪!怪!怪!怪!
ebfm 2003-04-15 04:09:48 #include <stdio.h>
main()
{
FILE * input_file_p;/* File Pointer for the input file */
char tmp;
char tmpbuff[256];
int usage[24][60];
int i;
int hour_1, min_1, hour_2, min_2;
input_file_p = fopen("testing.log", "r");
if (input_file_p == NULL)
{
printf("cannot open file testing.log\n");
exit(1);
}
for( i=0; i<24; i++)
{
memset( usage[i], 0, sizeof(60));
}
while (fgets( tmpbuff, sizeof(tmpbuff), input_file_p ) != NULL)
{
char tmp[64];
/* get 1st hour number */
strcpy(tmp, &tmpbuff[47], 2);
tmp[3] = '\0';
hour_1 = atoi(tmp);
/* get 1st min number */
strcpy(tmp, &tmpbuff[50], 2);
tmp[3] = '\0';
min_1 = atoi(tmp);
/* get 2st hour number */
strcpy(tmp, &tmpbuff[63], 2);
tmp[3] = '\0';
hour_2 = atoi(tmp);
/* get 2st min number */
strcpy(tmp, &tmpbuff[66], 2);
tmp[3] = '\0';
min_2 = atoi(tmp);
printf("%d %d %d %d\n", hour_1, min_1, hour_2, min_2);
}
}
为什么只能输出[47]第一个的值?后面三个值呢?