| | |
need help for saving high scores
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2006
Posts: 1
Reputation:
Solved Threads: 0
have prepared a code in c++ to save high scores and it is working well when i compile it in turbo c++and run the code .
but when i exit from the turbo c++ , the file to which i saved the high scores get corrupted and so when i again takes the turbo c++ , the files which i have written to the file are all missing . please help me . here is the code
but when i exit from the turbo c++ , the file to which i saved the high scores get corrupted and so when i again takes the turbo c++ , the files which i have written to the file are all missing . please help me . here is the code
c Syntax (Toggle Plain Text)
#include<iostream.h> #include<fstream.h> #include<string.h> #include<conio.h> struct highscore { char name[50]; int score; }; main() { int i,j,tempscore,tempno; char empty[]={"empty"}; ifstream fin("highscore.txt"); ofstream fout("highscore.txt"); highscore h[11]; j=0; fin.seekg(0); while (fin) { fin.read((char*)&h[j],sizeof(highscore)); j++; } if (j==0) { for (i=0;i<10;i++) { strcpy(h[i].name,empty); h[i].score=0; } } fin.close(); cout<<"enter the name\n"; cin.getline(h[10].name,50); cout<<"enter the score\n"; cin>>h[10].score; tempscore=0; for (i=0;i<10;i++) { tempscore=0; for (j=i;j<11;j++) { if (h[j].score>=tempscore) { tempscore=h[j].score; tempno=j; } } char name[50]; int p; p=h[i].score; h[i].score=h[tempno].score; h[tempno].score=p; strcpy(name,h[i].name); strcpy(h[i].name,h[tempno].name); strcpy(h[tempno].name,name); } fout.seekp(0); for (i=0;i<10;i++) { fout.write((char*)&h[i],sizeof(highscore)); cout<<h[i].name<<"\t\t\t\t"<<h[i].score<<"\n"; } fout.close(); getch(); }
Last edited by ~s.o.s~; Nov 2nd, 2006 at 1:38 pm.
![]() |
Similar Threads
- Runescape (Geeks' Lounge)
- Really really strugglisng with Jlist (Java)
- Creating Login (Java)
- need help with pickling please (Python)
- Totally lost...help with hijackthis.log (Viruses, Spyware and other Nasties)
- High Scores (C)
Other Threads in the C++ Forum
- Previous Thread: Initializing Multidimensional Arrays plz help!
- Next Thread: Adding a part to code
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






