Hi!
I have a task to made and I'm behind problem i cant cet over of..
The aim of little program is to handle data from .txt file..
It's written like this:
AEGVIIDU 6:25 7:17 8:20 10:20 13:30
MUSTJÕE 6:34 7:26 8:29 10:29 13:39
VIKIPALU 6:37 7:29 8:32 10:32 13:42
KEHRA 6:43 7:35 8:38 10:33 13:48
PARILA 6:46 7:38 8:41 10:41 13:51
RAASIKU 6:53 7:45 8:48 10:48 13:58
ARUKÜLA 6:58 7:50 8:53 10:53 14:03
KULLI 7:02 7:54 8:57 10:57 14:07
with tabulations between them..
What I'd like to know is that how would program understand that there is now end of line or char *pos1; which contains time usually,doesn't contain nothing..
I add my current code aswell,maybe some would find it helpful
char kell[20];
char kell2[20];
char *pos1;
int summa,j=0,n=0;
char *info[30];
int main(int argc, char* argv[])
{
FILE *fp;
char *pos;
int i,k;
char jaam[30];
char fail[]=("aegviidu.txt");
char rida[120];
char *eraldaja=" \t\n";
fp=fopen(fail,"r");
int vahe(char*,char*);
//printf("Mis viga on?\n");
if (!fp){
printf("Faili %s avamine abaõnnestus\n",fail);
getch();
return 1;
}
/*printf("Sisesta 1. kellaaeg:");
scanf("%s",kell1);
printf("Sisesta 2. kellaaeg:");
scanf("%s",kell2);
vahe(kell1,kell2);
*/
while(1)
{
fgets(rida,sizeof(rida),fp);
info[j] = new char[9];
strcpy(info[j],rida);
j++;
if (feof(fp)) break;
}
n=j;
algus:
printf("Sisesta otsitava jaama nimi,lopetamiseks vajuta +:");
scanf("%s",&jaam);
if (*jaam=='+') goto lopp;
for (k=0;k<sizeof(jaam);k++){
printf("%s\n",*jaam+k);
}
/*//printf("kokku on %u tahte\n",strlen(jaam));
for (i=0;i<strlen(jaam);i++){
toupper(jaam);
}
printf("%c,jaam\n");*/
printf("Sisesta kellaaeg:");
scanf("%s",&kell);
for (j=0;j<n-1;j++){
//printf("Mine perse\n");
printf("%s\n",info[j]);
if (strncmp(info[j],jaam,4)==0){
pos=strtok(info[j],"\t");
//printf("%s\n",pos);
uuesti:
//if(*pos1==':'){printf("Jww\n"); }
pos1=strtok(NULL,"\t");
//if(*pos1=='\n'){printf("Jww\n"); }
//else printf("Sisetatud jaama ei leidu\n");
//printf("%s\n",pos1);
vahe(kell,pos1);
//printf("summa on %d\n",summa);
if (summa<0) goto uuesti;
}
//printf("Jargmine rong antud jaamast väljub %d minuti pärast\n",summa);
}
//printf("Jargmine rong antud jaamast väljub %d minuti pärast\n",summa);
printf("Jargmine rong antud jaamast väljub %d minuti pärast\n",summa);
goto algus;
lopp:
fclose(fp);
return 0;
}
int vahe(char*,char*){
int tund,minut,summa1,summa2;
sscanf(kell,"%d:%d",&tund,&minut);
summa1=tund*60+minut;
sscanf(pos1,"%d:%d",&tund,&minut);
summa2=tund*60+minut;
summa=summa2-summa1;
return summa;
}
And the program has to tell when next train leaves from this station,user gives station name and current time..
Problem comes when last train for today has left
Sorry for my english
roland
I have a task to made and I'm behind problem i cant cet over of..
The aim of little program is to handle data from .txt file..
It's written like this:
AEGVIIDU 6:25 7:17 8:20 10:20 13:30
MUSTJÕE 6:34 7:26 8:29 10:29 13:39
VIKIPALU 6:37 7:29 8:32 10:32 13:42
KEHRA 6:43 7:35 8:38 10:33 13:48
PARILA 6:46 7:38 8:41 10:41 13:51
RAASIKU 6:53 7:45 8:48 10:48 13:58
ARUKÜLA 6:58 7:50 8:53 10:53 14:03
KULLI 7:02 7:54 8:57 10:57 14:07
with tabulations between them..
What I'd like to know is that how would program understand that there is now end of line or char *pos1; which contains time usually,doesn't contain nothing..
I add my current code aswell,maybe some would find it helpful
char kell[20];
char kell2[20];
char *pos1;
int summa,j=0,n=0;
char *info[30];
int main(int argc, char* argv[])
{
FILE *fp;
char *pos;
int i,k;
char jaam[30];
char fail[]=("aegviidu.txt");
char rida[120];
char *eraldaja=" \t\n";
fp=fopen(fail,"r");
int vahe(char*,char*);
//printf("Mis viga on?\n");
if (!fp){
printf("Faili %s avamine abaõnnestus\n",fail);
getch();
return 1;
}
/*printf("Sisesta 1. kellaaeg:");
scanf("%s",kell1);
printf("Sisesta 2. kellaaeg:");
scanf("%s",kell2);
vahe(kell1,kell2);
*/
while(1)
{
fgets(rida,sizeof(rida),fp);
info[j] = new char[9];
strcpy(info[j],rida);
j++;
if (feof(fp)) break;
}
n=j;
algus:
printf("Sisesta otsitava jaama nimi,lopetamiseks vajuta +:");
scanf("%s",&jaam);
if (*jaam=='+') goto lopp;
for (k=0;k<sizeof(jaam);k++){
printf("%s\n",*jaam+k);
}
/*//printf("kokku on %u tahte\n",strlen(jaam));
for (i=0;i<strlen(jaam);i++){
toupper(jaam);
}
printf("%c,jaam\n");*/
printf("Sisesta kellaaeg:");
scanf("%s",&kell);
for (j=0;j<n-1;j++){
//printf("Mine perse\n");
printf("%s\n",info[j]);
if (strncmp(info[j],jaam,4)==0){
pos=strtok(info[j],"\t");
//printf("%s\n",pos);
uuesti:
//if(*pos1==':'){printf("Jww\n"); }
pos1=strtok(NULL,"\t");
//if(*pos1=='\n'){printf("Jww\n"); }
//else printf("Sisetatud jaama ei leidu\n");
//printf("%s\n",pos1);
vahe(kell,pos1);
//printf("summa on %d\n",summa);
if (summa<0) goto uuesti;
}
//printf("Jargmine rong antud jaamast väljub %d minuti pärast\n",summa);
}
//printf("Jargmine rong antud jaamast väljub %d minuti pärast\n",summa);
printf("Jargmine rong antud jaamast väljub %d minuti pärast\n",summa);
goto algus;
lopp:
fclose(fp);
return 0;
}
int vahe(char*,char*){
int tund,minut,summa1,summa2;
sscanf(kell,"%d:%d",&tund,&minut);
summa1=tund*60+minut;
sscanf(pos1,"%d:%d",&tund,&minut);
summa2=tund*60+minut;
summa=summa2-summa1;
return summa;
}
And the program has to tell when next train leaves from this station,user gives station name and current time..
Problem comes when last train for today has left
Sorry for my english
roland