Solved

organiser program

Posted on 2004-03-22
9
191 Views
Last Modified: 2010-04-15
hi, can u pleae help me with this program im tryin to solve, im an dead stuck, below i have stated the specifcation:

My task is to develop a text-based menu driven electronic organiser application   As well as its normal functions, it must also create a text file of specific records with appropriate fields for transfer of contact details to a mobile phone.

im am required to use a menu based system in the layout below:

1)      The menu.

      The menu structure will contain the following entries

•      Create an entry
•      Amend/Delete an entry
•      Search for an entry
•      Create mobile phone transfer file
•      Quit the application

Below i have listed the file processing specification for the program:
      
      2)      File Processing
      
Upon execution the application will ask for the name of the ‘master file’, which will then be supplied by the user.  All of the records in the master file will then be read into       an array before any other processing will occur.  Upon the user asking to ‘Quit’ the application, the user will be asked if the master file should be updated, but only if records have been created/amended and/or deleted.  The structure of a master file       record is as follows:
      
                  Surname Firstname Address_Line_1 Address_Line_2 Address_Line_3
                  Postcode Home_Number Mobile_Number Email_Address Mobile_Indicator
      
Each field is separated by a space and the same code given in the lectures will also allow each record to be separated by a new-line ‘\n’ character so it will be easy to create a file of test data in an editor.  One problem you will have is the presence of ‘ ‘ space characters in some of the fields.  You should assume that all fields could hold space characters and when writing out the master file replace all spaces with a field with the ‘_’ underscore character and when reading it in, replace all ‘_’ underscore characters within each field with a ‘space’ character.
      
When asked to generate a mobile phone transfer file, the program will ask the user for a filename, which will then be used to save the transfer data in.  Only the records with the ‘Mobile_Indicator’ set to ‘true’ will be transferred to the transfer file and only the       following fields will be transferred for each of those records:
      
                  Person_ID, Number
      
The ‘Person_ID’ is made upon of the ‘Firstname’ and  ‘Surname’ fields concatenated together with the word ‘Mobile’ or ‘Home’ appended if the ‘Mobile_number’ field or ‘Home_Number’ field is used.  Each part of the ‘Person_ID’ field will be separated by an ‘_’ underline character.  If a master record has data in both numbers then two transfer records should be created.  One for the mobile number and one for the home number. Example, one record with the mobile number will be:
      
            Joe_Bloggs_Mobile 0123456789

The program also has to be able to search, I have listed the search  specification below:

      3)      Internal Record Processing
      
            Creating a record will simply mean adding a new record to the next empty element of       the master array.  You should use the ‘strupr’ function from the <string.h> library,       which will convert all characters in a string to uppercase.  If you do this for all user       input for record fields then this will make searching for a record easier.  Use the IDE       help system to find out more about the function. Deleting a record will mean moving       all the records that follow the record to be deleted up an element so that the record to       be deleted is over-written by the next record and so on.  You should store a record in       the array as a ‘struct’ so that you can easily access all of the fields separately.
      
            Searching should be allowed on the following fields:
      
                  Surname, Post-code and/or Email Address
      
      
      I would much appreciate it you could help me, thanks
0
Comment
Question by:markp370
  • 4
  • 2
9 Comments
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 10653319
What part are you having problems with?  This looks like a schoolwork assignment.
It is against the EE terms of membership for experts to do your homework for you.

We can help you overcome problems you encounter, but "im an dead stuck" is not
really a sufficient description of your problem for us to go on.

0
 

Author Comment

by:markp370
ID: 10653387
its not, sos im just being to detailed, it is a tutorial im doin for my degree,just for practice,the main part im havin a problem with is the part where i am asked to allow the user to input the name of the master file, where the data is be stored and implmenting it,
0
 

Author Comment

by:markp370
ID: 10653436
i just really need help with the structure of the program, im pretty new to programming an im finding the books i have which are the reccomended books arent helping, i am getting better but slowly as u can see,
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:markp370
ID: 10653476
i have used the example below to try and understand how to relate the menu to each part but have had no success (even though it has nothing to do with the problem):


#include <stdio.h>
#include <stdlib.h>

struct listNode {   /* self-referential structure */
   char data;
   struct listNode *nextPtr;
};

typedef struct listNode ListNode;
typedef ListNode *ListNodePtr;

void insert( ListNodePtr *, char );
char delete( ListNodePtr *, char );
int isEmpty( ListNodePtr );
void printList( ListNodePtr );
void instructions( void );

int main()
{
   ListNodePtr startPtr = NULL;
   int choice;
   char item;

   instructions();  /* display the menu */
   printf( "? " );
   scanf( "%d", &choice );

   while ( choice != 3 ) {

      switch ( choice ) {
         case 1:
            printf( "Enter a character: " );
            scanf( "\n%c", &item );
            insert( &startPtr, item );
            printList( startPtr );
            break;
         case 2:
            if ( !isEmpty( startPtr ) ) {
               printf( "Enter character to be deleted: " );
               scanf( "\n%c", &item );

               if ( delete( &startPtr, item ) ) {
                  printf( "%c deleted.\n", item );
                  printList( startPtr );
               }
               else
                  printf( "%c not found.\n\n", item );
            }
            else
               printf( "List is empty.\n\n" );

            break;
         default:
            printf( "Invalid choice.\n\n" );
            instructions();
            break;
      }

      printf( "? " );
      scanf( "%d", &choice );
   }

   printf( "End of run.\n" );
   return 0;
}

/* Print the instructions */
void instructions( void )
{
   printf( "Enter your choice:\n"
          "   1 to insert an element into the list.\n"
          "   2 to delete an element from the list.\n"
          "   3 to end.\n" );
}

/* Insert a new value into the list in sorted order */
void insert( ListNodePtr *sPtr, char value )
{
   ListNodePtr newPtr, previousPtr, currentPtr;

   newPtr = malloc( sizeof( ListNode ) );

   if ( newPtr != NULL ) {     /* is space available */
      newPtr->data = value;
      newPtr->nextPtr = NULL;

      previousPtr = NULL;
      currentPtr = *sPtr;

      while ( currentPtr != NULL && value > currentPtr->data ) {
         previousPtr = currentPtr;          /* walk to ...   */
         currentPtr = currentPtr->nextPtr;  /* ... next node */
      }

      if ( previousPtr == NULL ) {
         newPtr->nextPtr = *sPtr;
         *sPtr = newPtr;
      }
      else {
         previousPtr->nextPtr = newPtr;
         newPtr->nextPtr = currentPtr;
      }
   }
   else
      printf( "%c not inserted. No memory available.\n", value );
}

/* Delete a list element */
char delete( ListNodePtr *sPtr, char value )
{
   ListNodePtr previousPtr, currentPtr, tempPtr;

   if ( value == ( *sPtr )->data ) {
      tempPtr = *sPtr;
      *sPtr = ( *sPtr )->nextPtr;  /* de-thread the node */
      free( tempPtr );             /* free the de-threaded node */
      return value;
   }
   else {
      previousPtr = *sPtr;
      currentPtr = ( *sPtr )->nextPtr;

      while ( currentPtr != NULL && currentPtr->data != value ) {
         previousPtr = currentPtr;          /* walk to ...   */
         currentPtr = currentPtr->nextPtr;  /* ... next node */
      }

      if ( currentPtr != NULL ) {
         tempPtr = currentPtr;
         previousPtr->nextPtr = currentPtr->nextPtr;
         free( tempPtr );
         return value;
      }                                                        
   }

   return '\0';
}

/* Return 1 if the list is empty, 0 otherwise */
int isEmpty( ListNodePtr sPtr )
{
   return sPtr == NULL;
}

/* Print the list */
void printList( ListNodePtr currentPtr )
{
   if ( currentPtr == NULL )
      printf( "List is empty.\n\n" );
   else {
      printf( "The list is:\n" );

      while ( currentPtr != NULL ) {
         printf( "%c --> ", currentPtr->data );
         currentPtr = currentPtr->nextPtr;
      }

      printf( "NULL\n\n" );
   }
}
0
 
LVL 2

Accepted Solution

by:
Avik77 earned 125 total points
ID: 10660451
Hi markp370,
     If u r familiar to Linux enviornment u can use the dbm database routines and access functions to implement ur master/transaction type problem u have discussed about.
OTHERWISE

1) Make an array of stuctures like
  struct elec_org{
    char surname[20];
    char firstname[20];
    ...
  }elec[50];// say for 50 records

2) Input the file name by
     scanf("%s",filename);FILE * master;
     master=fopen(filename,"r");
3) read each data through from the masterfile by
   fgets(line,MAX,master);
  where line is a char * pointer, MAX can be #defined to ur recordlength in bytes(or no. of characters) and master is the pointer to the FILE structure for ur master file.
4) while(fgets(line,MAX,master)!=0){
      rec=1; // track the number of fields
      i=0;  // move through the record
     while(line[i]!='\n'){ // till the end of record
       j=0;
       while(line[j]!=' '){ // till the end of fields
        switch(rec){
          case 1: // first field
                    if(line[j]=='_'){temp[i].surname[j]=' ');}
                    else{temp[i].surname[j]=line[j]; }
                    j++;i++;
                    break;
          case 2: //thus for other fields
 
     ......
          }
        }      
        i++;rec++; // advance to next field
      }

Although I could'nt wrap it up nicely but I think u could have figured a bit if u would go through my code.
5)Next  comes ur routines for addition, deletion etc. Hey, wait u must now close the master file after reading.
6) any updates will straight away go to the array of structure.
 During updation u can open it in the write mode and apply a reverse processing like extracting the fields from structure array and replacing '_' by ' ' and building a string with a '\n' appended at its end and seperator between each fields. and writing that string into the master file by fputs(ln,master)
other works are pretty easy !!
Good luck

Avik.
0
 

Author Comment

by:markp370
ID: 10660508
thanks for that help, its much appreciated, it has helped a lot, thanks

markp
0
 
LVL 2

Expert Comment

by:Avik77
ID: 10706605
Hi markp370,
          if ur really benefitted from this, then u can also help me out by accepting the answer and awarding the points.
Just a request ;)
Avik.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

707 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

13 Experts available now in Live!

Get 1:1 Help Now