Search a File for a specified character

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • FraterVL
    New Member
    • Nov 2008
    • 3

    Search a File for a specified character

    I am currently working on an assignment for school. I am writing a grade book program. So far I have written code to show all current grades from a file, input new grades to the file and exiting the program. My problem is that I need to search the file for a specified character (the grade) and this has me confused.
    How would I go about searching a text file for a grade and displaying only the relevant entries?

    Any and all help is greatly appreciated.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    I'm not sure what you mean.

    You say a) you can write the data to the file and b) read it back, so what's the problem?

    Just open the file, read the data and search the data for the pertinant values. You do not actually need to seach the disc file itself. This can be done but in your case is not necessary,

    Comment

    • FraterVL
      New Member
      • Nov 2008
      • 3

      #3
      I apologize if I was unclear. What I meant to say was that I need to search inside the text file (not the disk) and find all instances of the grade that was given by the user then display all matching results.

      Sort of:
      // what follows is really bad pseudo code

      user inputs grade to search for
      program searches whatever.txt
      displays all matching results.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        It looks like you want to search whatever.txt.

        What I'm saying is that you read whatever.txt into memory and search that memory. Probably that means an array of some sort.

        So your pseudo-code is more like:

        1) open whatever.txt
        2) read data into memory
        3) get search value from user
        4) search memory for value

        ?

        Comment

        • FraterVL
          New Member
          • Nov 2008
          • 3

          #5
          Exactly

          p.s. thanks for being so patient with me.

          Comment

          Working...