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. C++ Help Needed

C++ Help Needed

Scheduled Pinned Locked Moved C / C++ / MFC
c++visual-studiohelpquestionannouncement
8 Posts 3 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.
  • V Offline
    V Offline
    vivekphlp
    wrote on last edited by
    #1

    Im doing a simple file programming in C++(im using turbo C version 3.0 editor) Iam using the Fstream class.. I can create & write datas into file successfully .. . But after some set of operations when I list the contents of the file. I get some ascii characters (like @ etc) or some irrelevant numbers. . . Can any one plz tell me what is happening. . . The same piece of code gives the correct output when I try it using VS 6.0 . . Plz help me. . ( VS6.0 is not recognizing clrscr() & gotoxy() – I had used conio.h) I want the program to work correctly from my Turbo C compiler .. .(its being used in my College) Thanks in Advance . .

    Proud To Be an Indian

    M B 2 Replies Last reply
    0
    • V vivekphlp

      Im doing a simple file programming in C++(im using turbo C version 3.0 editor) Iam using the Fstream class.. I can create & write datas into file successfully .. . But after some set of operations when I list the contents of the file. I get some ascii characters (like @ etc) or some irrelevant numbers. . . Can any one plz tell me what is happening. . . The same piece of code gives the correct output when I try it using VS 6.0 . . Plz help me. . ( VS6.0 is not recognizing clrscr() & gotoxy() – I had used conio.h) I want the program to work correctly from my Turbo C compiler .. .(its being used in my College) Thanks in Advance . .

      Proud To Be an Indian

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      vivekphlp wrote:

      I want the program to work correctly from my Turbo C compiler .. .(its being used in my College)

      Wow....Turbo C 3.0 came out 16 years ago... Still, I would expect it to work (I guess).  Depends on the runtime library. Without seeing any code it's impossible to guess what's wrong. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      1 Reply Last reply
      0
      • V vivekphlp

        Im doing a simple file programming in C++(im using turbo C version 3.0 editor) Iam using the Fstream class.. I can create & write datas into file successfully .. . But after some set of operations when I list the contents of the file. I get some ascii characters (like @ etc) or some irrelevant numbers. . . Can any one plz tell me what is happening. . . The same piece of code gives the correct output when I try it using VS 6.0 . . Plz help me. . ( VS6.0 is not recognizing clrscr() & gotoxy() – I had used conio.h) I want the program to work correctly from my Turbo C compiler .. .(its being used in my College) Thanks in Advance . .

        Proud To Be an Indian

        B Offline
        B Offline
        bob16972
        wrote on last edited by
        #3

        vivekphlp wrote:

        VS6.0 is not recognizing clrscr() & gotoxy()

        Ah, I miss those two functions. I built some pretty snazzy apps for the convenience store industry in the 90's and those two made 80x25 character grid programming a snap. I somewhat recall that when I moved from Turbo C++ 3.0 to Visual C++ 6.0, I looked for those functions to see if I could port my apps to Windows console based apps but it ended in failure. Concerning your issue, as someone mentioned earlier, it would help to see the code snippets that are relevant to identify issues. Is it possible to post some source code snippets?

        V 1 Reply Last reply
        0
        • B bob16972

          vivekphlp wrote:

          VS6.0 is not recognizing clrscr() & gotoxy()

          Ah, I miss those two functions. I built some pretty snazzy apps for the convenience store industry in the 90's and those two made 80x25 character grid programming a snap. I somewhat recall that when I moved from Turbo C++ 3.0 to Visual C++ 6.0, I looked for those functions to see if I could port my apps to Windows console based apps but it ended in failure. Concerning your issue, as someone mentioned earlier, it would help to see the code snippets that are relevant to identify issues. Is it possible to post some source code snippets?

          V Offline
          V Offline
          vivekphlp
          wrote on last edited by
          #4

          I Use the following code 2 write to file -> b=l.newbook(); if(fiobook.eof()) fiobook.clear(); fiobook.seekp(0,ios::end); fiobook.write((char*)&b,sizeof(b)); gotoxy (10,24); cout<<"Do you want to continue Y/N?"; cin>>cx; cin.get(); ************************* where .. . .newbook is book library::newbook() { clrscr(); book b; gotoxy(10,10); cout<<"Acc No"; cin>>b.accno; cin.get(); gotoxy(10,12); cout<<"Title"; cin.getline(b.title,30); gotoxy(10,14); cout<<"Author"; cin.getline(b.author,30); gotoxy(10,16); cout<<"price"; cin>>b.price; gotoxy(10,18); cout<<"No of Copies"; cin>>b.nCopies; b.issued=0; b.memno=0; return b; } EVERYTHING WORKS FINE ... ******************************************** Then I use a function to display the contents . .. void library::list(fstream & fiobook) { clrscr(); book b; fiobook.clear(); fiobook.seekg(0); for(;;) { fiobook.read((char*)&b,sizeof(struct book)); if(fiobook.eof()) break; cout<<"Acc no "<Proud To Be an Indian

          B 2 Replies Last reply
          0
          • V vivekphlp

            I Use the following code 2 write to file -> b=l.newbook(); if(fiobook.eof()) fiobook.clear(); fiobook.seekp(0,ios::end); fiobook.write((char*)&b,sizeof(b)); gotoxy (10,24); cout<<"Do you want to continue Y/N?"; cin>>cx; cin.get(); ************************* where .. . .newbook is book library::newbook() { clrscr(); book b; gotoxy(10,10); cout<<"Acc No"; cin>>b.accno; cin.get(); gotoxy(10,12); cout<<"Title"; cin.getline(b.title,30); gotoxy(10,14); cout<<"Author"; cin.getline(b.author,30); gotoxy(10,16); cout<<"price"; cin>>b.price; gotoxy(10,18); cout<<"No of Copies"; cin>>b.nCopies; b.issued=0; b.memno=0; return b; } EVERYTHING WORKS FINE ... ******************************************** Then I use a function to display the contents . .. void library::list(fstream & fiobook) { clrscr(); book b; fiobook.clear(); fiobook.seekg(0); for(;;) { fiobook.read((char*)&b,sizeof(struct book)); if(fiobook.eof()) break; cout<<"Acc no "<Proud To Be an Indian

            B Offline
            B Offline
            bob16972
            wrote on last edited by
            #5

            I took another look around for the gotoxy stuff and to my embarrassment, there is a reference to this in Mr. Dunn's FAQ right here on CP. clrscr[^] gotoxy[^]

            B 1 Reply Last reply
            0
            • B bob16972

              I took another look around for the gotoxy stuff and to my embarrassment, there is a reference to this in Mr. Dunn's FAQ right here on CP. clrscr[^] gotoxy[^]

              B Offline
              B Offline
              bob16972
              wrote on last edited by
              #6

              I put some snippets together this morning over coffee using Mr. Dunn's information and came up with these. See if these might help you to use gotoxy and clrscr in Visual C++. #include "stdafx.h" #include #include #include bool gotoxy(int x, int y) { // Sets the cursor position COORD coord={x,y}; HANDLE hConsole=GetStdHandle(STD_OUTPUT_HANDLE); if (hConsole!=INVALID_HANDLE_VALUE) { if (SetConsoleCursorPosition(hConsole,coord)) { return true; } } return false; } bool ClrScr() { // Use a system call to clear the screen if (system("cls")!= -1) { return true; } return false; } bool clrscr() { // Use a custom function to clear the screen COORD origin={0}; CONSOLE_SCREEN_BUFFER_INFO conInfo={0}; HANDLE hConsole=GetStdHandle(STD_OUTPUT_HANDLE); if (hConsole!=INVALID_HANDLE_VALUE) { if (GetConsoleScreenBufferInfo(hConsole,&conInfo)) { int nLength=conInfo.dwSize.X*conInfo.dwSize.Y; DWORD dwNum(0); if (FillConsoleOutputAttribute(hConsole, conInfo.wAttributes, nLength,origin,&dwNum)) { dwNum=0; if (FillConsoleOutputCharacter(hConsole, (TCHAR)'\0',nLength,origin,&dwNum)) { if (gotoxy(origin.X,origin.Y)) { return true; } } } } } return false; } int main(int argc, char* argv[]) { printf("Hello World\n"); // ClrScr(); clrscr(); gotoxy(5,5); printf("Hello again\n"); return 0; }

              1 Reply Last reply
              0
              • V vivekphlp

                I Use the following code 2 write to file -> b=l.newbook(); if(fiobook.eof()) fiobook.clear(); fiobook.seekp(0,ios::end); fiobook.write((char*)&b,sizeof(b)); gotoxy (10,24); cout<<"Do you want to continue Y/N?"; cin>>cx; cin.get(); ************************* where .. . .newbook is book library::newbook() { clrscr(); book b; gotoxy(10,10); cout<<"Acc No"; cin>>b.accno; cin.get(); gotoxy(10,12); cout<<"Title"; cin.getline(b.title,30); gotoxy(10,14); cout<<"Author"; cin.getline(b.author,30); gotoxy(10,16); cout<<"price"; cin>>b.price; gotoxy(10,18); cout<<"No of Copies"; cin>>b.nCopies; b.issued=0; b.memno=0; return b; } EVERYTHING WORKS FINE ... ******************************************** Then I use a function to display the contents . .. void library::list(fstream & fiobook) { clrscr(); book b; fiobook.clear(); fiobook.seekg(0); for(;;) { fiobook.read((char*)&b,sizeof(struct book)); if(fiobook.eof()) break; cout<<"Acc no "<Proud To Be an Indian

                B Offline
                B Offline
                bob16972
                wrote on last edited by
                #7

                In regards to the strange characters your getting... What is book? Do you have the code snippet showing it's declaration?

                V 1 Reply Last reply
                0
                • B bob16972

                  In regards to the strange characters your getting... What is book? Do you have the code snippet showing it's declaration?

                  V Offline
                  V Offline
                  vivekphlp
                  wrote on last edited by
                  #8

                  "Book is a structure" struct book { int accno; char title[30]; char author[30]; float price; int issued; int nCopies; int memno; }; IM Using this structure in My CLASS class library { book book1; member member1; public: book newbook(); void list(fstream &); void issuebook(fstream &, fstream &); void returnbook(fstream &, fstream &); member newmember(); void listofmembers(fstream &); } ;

                  Proud To Be an Indian

                  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