If i got the following file
1 station1 1
2 station2 2
3 station3 3
4 station4 4
5 station5 5
6 station6 6
7 station7 7
8 station8 8
9 station9 9
10 station10 10
and i want to read the data of the first and last line. I tried this:
for (i=0; i<n; i++) {
ret = fork();
if (ret == 0) {
fscanf(fstation,"%d %s %d",id, station, num);
printf("Identifier is %d %s %d \n",id,station,num);
exit(0);
}else{wait(&st);}
}
And the output is this.
Identifier is 0 0
Identifier is 0 0
Identifier is 0 0
Identifier is 0 0
Identifier is 0 0
Identifier is 0 0
Identifier is 0 0
Identifier is 0 0
Identifier is 0 0
Identifier is 0 0
It doesen't works very well, what im doing wrong? EDIT: sorry for the misunderstanding, i tried to translate part of the code to make it more understandable.