By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,465 Members | 1,593 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,465 IT Pros & Developers. It's quick & easy.

Search a File for a specified character

P: 3
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.
Nov 18 '08 #1
Share this Question
Share on Google+
4 Replies

Expert Mod 5K+
P: 9,197
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,
Nov 18 '08 #2

P: 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.
Nov 18 '08 #3

Expert Mod 5K+
P: 9,197
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

Nov 18 '08 #4

P: 3

p.s. thanks for being so patient with me.
Nov 18 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.