User Input and File Handling

This is a discussion on User Input and File Handling within the Game Programming forums, part of the General Programming Boards category; In my game I am trying to get the user to type in his/her name and write the name and ...

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    16

    User Input and File Handling

    In my game I am trying to get the user to type in his/her name and write the name and score into a file.

    Here is some of what I have

    Code:
    void GetName()
    {
      newname[0] = ' ';
      length = 0;
      clear_keybuf();
      while(!key[KEY_ENTER])
      {
        clear_bitmap(buffer);
        blit((BITMAP*)data[newscore].dat, buffer, 0, 0, 155, 100, 333, 204);
    
        if(keypressed())
        {
          ch = readkey() & 0x00ff;
          if(length < 20)
          {
            newname[length + 1] = ' ';
            newname[length] = ch;
            length++;
          }
        }
    
        if(key[KEY_BACKSPACE] && length > 0)
        {
          newname[length - 1] = ' ';
          length--;
        }
    
        if(key[KEY_SPACE])
        {
          newname[length + 1] = ' ';
          newname[length] = '_';
        }
    
        textout_centre(buffer, font, newname, 320, 188, -1);
        blit(buffer, screen, 0, 0, 0, 0, 640, 480);
      }
    
      score10 = score9;
      score9 = score8;
      score8 = score7;
      score7 = score6;
      score6 = score5;
      score5 = score4;
      score4 = score3;
      score3 = score2;
      score2 = score1;
      score1 = score;
    
      name10 = name9;
      name9 = name8;
      name8 = name7;
      name7 = name6;
      name6 = name5;
      name5 = name4;
      name4 = name3;
      name3 = name2;
      name2 = name1;
      name1 = newname;
    
      ofstream fout;
      fout.open("HSL.dat");
      fout << name1 << endl;
      fout << score1 << endl;
      fout << name2 << endl;
      fout << score2 << endl;
      fout << name3 << endl;
      fout << score3 << endl;
      fout << name4 << endl;
      fout << score4 << endl;
      fout << name5 << endl;
      fout << score5 << endl;
      fout << name6 << endl;
      fout << score6 << endl;
      fout << name7 << endl;
      fout << score7 << endl;
      fout << name8 << endl;
      fout << score8 << endl;
      fout << name9 << endl;
      fout << score9 << endl;
      fout << name10 << endl;
      fout << score10 << endl;
      fout.close();
      HighScore();
    }

    Now it doesnt put info into the file like it should. And if the user types nothing it messes up everything.

    I use Allegro with Dev-C++, If you see anything I am doing wrong plese let me know.
    I am using Allegro and Dev-C++.

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    16
    Shoud I use something other than
    Code:
    name2 = name1
    Would strcpy() or a bitwise operator br better?

    I really just want to get this through so I can put the tetris thing behind me.........
    Last edited by Disturbed1; 05-27-2003 at 12:55 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  3. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 01:20 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21