N
Neel
Hi friends,
I 'm facing some weird problem with file handling.
When I open the file and read the contents, it works fine but when I
do it again for the second time In a loop, it fails...
my code is...
while(1){
fp=fopen("tram_schedule.txt","r");
if(fp==0){
char errMsg[]="Error: Unable to get tram schedules. pls try again
later";
puts("Error");
if(send(tmp->sock, errMsg, strlen(errMsg), 0)==-1){
cout<<"Error: "<<strerror(errno)<<endl;
exit(0);
}
close(tmp->sock);
}
else{
while(!feof(fp)){
fgets(myData,100,fp);
strcat(infoToSend,myData);
}
}
//puts(infoToSend);
cout<<"socket id: "<<tmp->sock<<endl;
fclose(fp);
}
'm opening and closing the file in every iteration.
can anyone please help me solve this issue?
Thanks in advance
I 'm facing some weird problem with file handling.
When I open the file and read the contents, it works fine but when I
do it again for the second time In a loop, it fails...
my code is...
while(1){
fp=fopen("tram_schedule.txt","r");
if(fp==0){
char errMsg[]="Error: Unable to get tram schedules. pls try again
later";
puts("Error");
if(send(tmp->sock, errMsg, strlen(errMsg), 0)==-1){
cout<<"Error: "<<strerror(errno)<<endl;
exit(0);
}
close(tmp->sock);
}
else{
while(!feof(fp)){
fgets(myData,100,fp);
strcat(infoToSend,myData);
}
}
//puts(infoToSend);
cout<<"socket id: "<<tmp->sock<<endl;
fclose(fp);
}
'm opening and closing the file in every iteration.
can anyone please help me solve this issue?
Thanks in advance