C++ Help Needed
-
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
-
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
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:
-
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
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?
-
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?
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
-
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
-
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; }
-
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
-
In regards to the strange characters your getting... What is book? Do you have the code snippet showing it's declaration?
"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