Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Random Access Files

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I've just started using random access files and need to know what i'm doing wrong.

I've made a test program (just to learn how to work with them) but it dosn't work properlly.

The first part of the program reads in names entered by the user and should work like this:

read in name from user
write to file
repeat until user exits
then add '.' to the end of the file

Then the second reads in the values like this:

read in name
display name
repeat this until '.' char found

The first part of the program definately works. The names get entered and stored in the file and the '.' char gets added to the end of the file.

The second part of the program does not work. If I only enter 1 name in the first program then the second program works, but if I enter more than 1 name then it loops forever outputting null as the name.

This is my code for reading in the names:

Ignore the empty catch statements as this was just a quick test. Also, there's an int called nameNumber in there which is just a number assigned to the name when it is entered in program 1.

Can anyone see what i've done worng?

Cheers,

J
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please do not cross post.
 
Do not set lab on fire. Or this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
    Bookmark Topic Watch Topic
  • New Topic