Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 19th, 2005, 7:50 AM   #41
ivan
Professional Programmer
 
ivan's Avatar
 
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 3 ivan is on a distinguished road
I don't know, maybe you should give all you energy into learning JAVA first. I don't think that it's a good idea learning many different prog languages in the same time.
ivan is offline   Reply With Quote
Old Oct 19th, 2005, 7:56 AM   #42
tomwdrake
Newbie
 
tomwdrake's Avatar
 
Join Date: Oct 2005
Location: London
Posts: 25
Rep Power: 0 tomwdrake is on a distinguished road
Question

Ok. If that is your advice that is what I shall do for now certainly. Thanks, theres lots of java programmers on here to help me learn that better?
__________________
-----------------------------------------------------
________||| Tom |||_______
-----------------------------------------------------
tomwdrake is offline   Reply With Quote
Old Oct 19th, 2005, 8:27 AM   #43
peace_of_mind
Professional Programmer
 
peace_of_mind's Avatar
 
Join Date: Sep 2004
Location: Hell if I know most of the time
Posts: 439
Rep Power: 4 peace_of_mind is on a distinguished road
Send a message via MSN to peace_of_mind Send a message via Yahoo to peace_of_mind
If it's C programming you've decided to go with, I'm in. peaceofmind53@gmail is me addy. I'm gonna have a mod move this to the C forum, since it's not really assembly related anymore.

EDIT: add a .com to that address, of course :p
__________________
Amateurs built the ark
Professionals built the Titanic

peace_of_mind is offline   Reply With Quote
Old Oct 19th, 2005, 8:52 AM   #44
ivan
Professional Programmer
 
ivan's Avatar
 
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 3 ivan is on a distinguished road
Yes it makes sence to move in the C forum. I will send you my current source code or you can copy/paste a little older version in another thread started by myself.
ivan is offline   Reply With Quote
Old Oct 19th, 2005, 9:02 AM   #45
Prm753
Professional Programmer
 
Prm753's Avatar
 
Join Date: Oct 2005
Location: United States
Posts: 447
Rep Power: 3 Prm753 is on a distinguished road
Send a message via AIM to Prm753 Send a message via MSN to Prm753
ivan, sorry I didn't get back to you sooner. Here's my email: prm753@operamail.com
__________________
The world's first athletic computer geek!
The home of PrProgramsStudios
How not to post a question: <-- Please don't reply
Prm753 is offline   Reply With Quote
Old Oct 19th, 2005, 9:23 AM   #46
peace_of_mind
Professional Programmer
 
peace_of_mind's Avatar
 
Join Date: Sep 2004
Location: Hell if I know most of the time
Posts: 439
Rep Power: 4 peace_of_mind is on a distinguished road
Send a message via MSN to peace_of_mind Send a message via Yahoo to peace_of_mind
Quote:
Originally Posted by ivan
Yes it makes sence to move in the C forum. I will send you my current source code or you can copy/paste a little older version in another thread started by myself.
Send me the current source, if you don't mind.
__________________
Amateurs built the ark
Professionals built the Titanic

peace_of_mind is offline   Reply With Quote
Old Oct 19th, 2005, 12:51 PM   #47
ivan
Professional Programmer
 
ivan's Avatar
 
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 3 ivan is on a distinguished road
I posted here the code for everyone:

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

#define MAX 1000 /* max number of records */
#define ENTRY 32 /* max number of chars for name, surname and phone */

#define ONE 49
#define TWO 50
#define THREE 51
#define FOUR 52
#define FIVE 53
#define SIX 54
#define SEVEN 55
#define EIGHT 56    /* define ASCII values for numbers 1-8 */

void addRecord();
void delRecord();
int findFree();
void findRecord();
void listPeople();
void save();
void eraseAll();
void menu();
void showHelp();
void showRecord();
int freeSpace();

struct data 
{
       char name[ENTRY];
       char surname[ENTRY];
       char phone[ENTRY];
};

struct data People[MAX];

int main()
{
    
    /* Error checking for reading and creating the database file */
    
    FILE *fp;
        
    if ( (fp=fopen("phonebook.dat" , "r")) == NULL)
    {
         if( (fp=fopen("phonebook.dat" , "w")) == NULL ) 
         {
             puts( "Can not create the file! The program will exit\n" );
             system( "PAUSE" );
             exit(0);
         } /* if */
         
         save();
         
         fclose( fp );
    } /* if */
         
    fp=fopen("phonebook.dat" , "r");
         
    fread(People , sizeof People , 1 , fp);
   
    if (ferror(fp))
    {
            puts("An error occurred while reading file! The program will exit\n");
            system( "PAUSE" );
            fclose(fp);
            exit(0);
    } /* if */           
    
    
    
    
    puts( "**************************" );
    puts( "Phonebook 1.0 Beta by Ivan" );
    puts( "korhner5@neobee.net" );
    puts( "**************************\n\n" );
    
    showHelp();
       
    while (1)
    {
          rewind( stdin );   /* clears the STDIN */
          menu();
    } /* while */
    
} /* main */

void addRecord()
{
     int position;
     position = findFree();  /* find index of a free space in the array */
     
     if( position == -1 )    /* if there is not any space say that to user */
     {
         puts( "The list is full!" );
         return;
     } /* if */
     
     rewind(stdin);     /* clears the STDIN */
         
     puts( "Please enter name:" );
     fgets( People[position].name, ENTRY, stdin );
               
     rewind( stdin );     /* clears the STDIN */
     
     if( strlen( People[position].name ) <= 1 ) return;     /* if the user entered nothing, return */
     
     if ( strlen( People[position].name ) < ENTRY )     /* if the user entered a name with chars < ENTRY, then delete the newline char */ 
     {
          People[position].name[strlen( People[position].name ) - 1] = '\0';
     } /* if */
     
     while( strlen( People[position].surname ) <= 1 )
     {
            puts( "Please enter surname:" );
            fgets( People[position].surname, ENTRY, stdin );
     } /* while */       
     
     rewind( stdin );     /* clears the STDIN */
     
     if ( strlen( People[position].surname ) < ENTRY ) 
     {
          People[position].surname[strlen( People[position].surname ) - 1] = '\0';
     } /* if */
     
      while( strlen( People[position].phone ) <= 1 )
     {
            puts( "Please enter phone number:" );
            fgets( People[position].phone, ENTRY, stdin );
     } /* while */      
          
     rewind( stdin );     /* clears the STDIN */
     
     if ( strlen( People[position].phone ) < ENTRY ) 
     {
          People[position].phone[strlen( People[position].phone ) - 1] = '\0';
     } /* if */
    
     
} /* addRecord */

void delRecord()
{
     char name[ENTRY ];
     char surname[ENTRY];
     
     int i;
     
     rewind( stdin );    /* clears the STDIN */
     
     puts( "Please enter name you want to delete: " );
     fgets( name, ENTRY, stdin );
     
     puts( "Please enter surname you want to delete: " );
     fgets( surname, ENTRY, stdin );
     
     for( i=0; i<MAX; i++ )     /* check for the name and surname the user entered */
     {
          if( strcmp( People[i].name, name ) == 0 )
          {
              if ( strcmp( People[i].surname, surname ) == 0 ) *People[i].name = '\0';     /* when found deleted it */
              puts( "Deleted!\n" );
          } /* if */
     } /* for */
     
} /* delRecord */
     

int findFree()     /* find free index of the array and return it */
{
    int i;
    for(i=0; i<MAX; i++) 
    {
         if( !*People[i].name )
         {
             return i;
             break;
         } /* if */
             
    } /* for */
    return -1;     /* if list is full return -1 */
} /* findFree */

void findRecord()
{
     int i;
     char input[30];
     
     rewind( stdin );     /* clears the STDIN */
     
     puts( "Enter what you want to search: " );
     gets( input );
     
     if( strlen( input ) == 0 )
     {
         rewind( stdin );
         return;
     } /* if */
     
     for( i=0; i<MAX; i++)     /* check for user input in names, surnames, and phones */
     {
          if( (strcmp( People[i].name, input ) == 0) || (strcmp( People[i].surname, input ) == 0) || (strcmp( People[i].phone, input ) == 0)  ) 
          {
              showRecord(i);
          } /* if */
     } /* for */
     
} /* findRecord */
     
void listPeople()     /* list all the records */
{
     int i;
     for( i=0; i<MAX; i++ )
     {
          if( *People[i].name )     /* do not show empy records */
          {
              showRecord(i);
          } /* if */
     } /* for */ 
} /* listPeople */
     
void menu()
{
     char sel;
     
     puts( "Enter your choice ( 8 for help ):" );
     
     sel = fgetc( stdin );     /* read a char from STDIN */
     
     rewind( stdin );     /* clears the STDIN */
          
     if( sel<ONE || sel>EIGHT )     /* check if user entered a number between 1 and 8 */
     {
         puts( "Please enter a number between 1 and 8!\n" );
         return;
     } /* if */
     
     switch (sel)
     {
            case ONE:
                 save();
                 break;
                 
            case TWO:
                 eraseAll();
                 break;
                 
            case THREE:
                 addRecord();
                 break;
                                  
            case FOUR:
                 delRecord();
                 break;
                 
            case FIVE:
                 findRecord();
                 break;
                 
            case SIX:
                 listPeople();
                 printf( "\n--------------------------\n" );
                 printf( "Free space = %4d     %3d%% \n", freeSpace(), (100 * freeSpace()) / MAX );
                 printf( "Used space = %4d     %3d%% \n", MAX - freeSpace(), 100 - ((100 * freeSpace()) / MAX) );
                 printf( "--------------------------\n\n" );
                 break;
                 
            case SEVEN:
                 exit(0);
                 
            case EIGHT:
                 showHelp();
                 break;
                 
            default:     
                 puts( "Please enter a number between 1 and 8!\n" );
                 break;               
     } /* switch */       
} /* menu */

void save()
{
    FILE *fp;

    if ( (fp=fopen("phonebook.dat" , "w")) == NULL)
    {     /* handle file errors */
      printf("cannot open file\n");
      return;
    } /* if */
    
    fwrite(People , sizeof People , 1 , fp);    /* main instruction that writes the array */
    
    if (ferror(fp))     /* check for file errors */
    {
         printf("An error occurred while writing file.\n");
         fclose(fp);
         return;
    } /* if */
    
    fclose(fp);
    
    puts("File has been saved!\n");
} /* save */

void eraseAll()     /* erase all records( only names ) */
{
     int i;
     
     for( i=0; i<MAX; i++)
     {
          *People[i].name = '\0';     /* clears every name */
     } /* for */
     
     puts( "All records have been deleted!\n" );
} /* eraseAll */
        
void showHelp()
{
     puts( "Save...........................1\n" );
     puts( "Reset..........................2\n" );
     puts( "Add new entry..................3\n" );
     puts( "Delete an entry................4\n" );
     puts( "Find...........................5\n" );
     puts( "List the file, view free space.6\n" );
     puts( "Exit...........................7\n" );

} /* showHelp */

void showRecord(int index)     /* prints the name, surname and phone of the People[index] */
{
     printf("\nName:        %s\n", People[index].name );
     printf("Surname:     %s\n", People[index].surname );
     printf("Phone:       %s\n\n", People[index].phone );
} /* showRecord */

int freeSpace()     /* calulates free space of the array */
{
     int i;
     int count = 0;
     
     for( i=0; i<MAX; i++)
     {
          if( !*People[i].name ) count++;
     } /* for */
     
     return count;
     
} /* freeSpace */
ivan is offline   Reply With Quote
Old Oct 19th, 2005, 8:47 PM   #48
nindoja
Programmer
 
Join Date: Jun 2005
Posts: 92
Rep Power: 4 nindoja is on a distinguished road
wow Ivan, I am impressed at your people skills. I know this is sorta off topic, but you are looking like you are a really friendly person, unlike most of the people that have come by lately. Keep it up, you are doing a good job.

@tom: There are some differences, but if you are going to program at all for a living, I would definately suggest learning c and/or c++. It will be a little ackward at first, but once you get a hold of not encapsulating everything, you will find that C/C++ is really easy to work with.
nindoja is offline   Reply With Quote
Old Oct 20th, 2005, 4:15 AM   #49
tomwdrake
Newbie
 
tomwdrake's Avatar
 
Join Date: Oct 2005
Location: London
Posts: 25
Rep Power: 0 tomwdrake is on a distinguished road
Hmm.. Maybe I'll try and learn C++ at the same time as java, given that their both object orietated - I can just transfer the techniques by translating the code... .... (please warn me if this is a ridiculous idea)
__________________
-----------------------------------------------------
________||| Tom |||_______
-----------------------------------------------------
tomwdrake is offline   Reply With Quote
Old Oct 20th, 2005, 7:17 AM   #50
ivan
Professional Programmer
 
ivan's Avatar
 
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 3 ivan is on a distinguished road
Quote:
but you are looking like you are a really friendly person
Well, I am trying...

@tomwdrake: You mean translating this to C++??? If so it could be done very easy. For java, I don't know. But I think it is not hard.
ivan is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:58 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC