Search and Sort in a Simple Database

Posted on 2004-11-16
Last Modified: 2010-04-15
Hello to anybody, I need help on creating a program that allowed the user to search or sort on a database on student information.

In this program each stduent has fields: name, student ID, phone number, and grade

-name field has student's last and first names
-student ID had five digits from 0 to 9
- phone number has 10 characters
-grade is an integer between 0 to 99

What the problem is that how will I create a string array or a multiarray string that allows the user's to search the database by student's name, studend ID, phone number or grade and sort the database by any of the four fields upon the user's choice then prints out all the records in the database in database in Ascending order.

I am not sure if I am clear enough on my question but if there is anything unclear please let me know. thank you
Question by:Ofakile1
    1 Comment
    LVL 45

    Accepted Solution

    Hi Ofakile1,

    You're going to need several things to organize the data in a way that makes access/sorting easy.  The easiest, though wordiest, approach will be to write a search routine for every field upon which you might want to search.

    Define a structure that defines the fields you want to track.  Below is an example.  Adjust it to fit your needs.

    typedef struct
      char LastName[20];
      char FirstName[20];
      int  ID;
      char Phone[11];
      int  Grade;
    } Student_t;

    If you'll store your data as an array of pointers to the records, sorting is very easy, as is searching.

    Student_t **StudentList = NULL;  /*  Array of student records  */
    int       StudentCount = 0;      /*  Number of records in the StudentList array  */

    From here, it's simply a matter of writing routines to AddStudent(), SortByName(), SearchByFirstName(), SearchByLastName(), etc.

    Good Luck!

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
    Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
    The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now