Thread: Reading Characters.

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    13

    Reading Characters.

    Ok, I have a saved file with the following information saved in binary format.

    Mdog*Mcat*

    My goal is to be able to read the file 1 char at a time,and when it reaches the '*' it puts a cout<<"\n"; in to make a new line. However, I am having trouble dealing with the primary code.
    When I try to read the file, it comes out like this.

    M2222
    d2222
    o2222
    g2222
    *2222
    (I have it set to display 1 char at a time, then show the whole thing)

    after, it displays...

    *2222 (only the last char is read.

    one thing to note is that to just get the basics running, the program will only read the first 5 characters.

    I could use some help getting this thing to work.
    Code:
    clrscr();
    	char ch ='\0';
    	int length;
      char * buffer;
      char * character;
    
      //Users *newrec;
    	int endloop=0; 
    	ifstream readfile;
    	readfile.open("Profiles.dat",ios::in |ios::binary);
    	readfile.seekg (0, ios::end);
    	  length = readfile.tellg();
    	  readfile.seekg (0, ios::beg);
    	  int k=0;
    	  character =new char[length];
    	  int b=0;
    	do
    	{
    
    	 buffer[b] = new char;
    	readfile.read (buffer,1);
    	cout <<buffer <<k <<endl;
    	k++;
    	readfile.seekg (0,ios::cur);
    	character[b]=buffer[b];
    	b++;
    	cout <<character[b]<<endl;
    	getch();
    
    	}while(k!=5);
    
    	readfile.close();
    	cout << "Load succesful";
    	clrscr();
      //cout <<character[length] <<endl;
      cout.write (buffer,k);
    	getch();

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    13
    bump

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Can you post:

    1) representation of the data in the file you read from
    2) representation of the data you want to output

    Kuphryn

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    13

    Talking

    thanks, but don't worry about it, I decided that I would just have the program make a new file for every person, like a game's save function. That should cut down on the amount of binary file navigating I have to do

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Okay. Cool.

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  2. Convert string of characters to integers
    By Digital_20 in forum C++ Programming
    Replies: 2
    Last Post: 04-02-2008, 09:40 PM
  3. problem in reading alphabets from file
    By gemini_shooter in forum C Programming
    Replies: 6
    Last Post: 03-09-2005, 01:49 PM
  4. Reading Characters from file into multi-dimensional array
    By damonbrinkley in forum C Programming
    Replies: 9
    Last Post: 02-24-2005, 01:31 PM
  5. Reading files with an unkown amount of characters
    By Zahl in forum C++ Programming
    Replies: 13
    Last Post: 10-10-2002, 02:04 PM