strings/input-output

This is a discussion on strings/input-output within the C++ Programming forums, part of the General Programming Boards category; I've been given an assignment which asks me to write a program that does the following: -Opens a file which ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    2

    strings/input-output

    I've been given an assignment which asks me to write a program that does the following:
    -Opens a file which contains 50 last names and student IDs
    -Gives the user the option of searching by last name or ID
    -If there is a match, both the name and ID will be printed.
    -If there is no match, an error statement is printed.

    I know how to get the program to open a file, but I'm not sure what to use for searching the file for a name. Any suggestions?

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Do you know the exact format of the file, for example:
    name id
    name id
    ...

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    2
    yes, its like

    Johnson 123-45-6789

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So read in the data into a data structure of your choosing (if it's always 50, then that suggests an array; if it's not always 50, then you'll probably want something dynamic); then as your user requests searches, you can search through the data structure to find the results.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. code output...
    By roaan in forum C Programming
    Replies: 6
    Last Post: 07-03-2009, 03:22 AM
  2. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  3. Replies: 4
    Last Post: 11-30-2005, 04:44 PM
  4. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 06:10 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM

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