Need Help Executing Program (suggestions from group added but not quite there yet) 
Author Message
 Need Help Executing Program (suggestions from group added but not quite there yet)

The following function in conjunction with a find record function
updates records in a database one at a time by using the email
address as a key. The find function takes the email address and
compares it to all the entries alreay in the database.

When it finds the email address it returns it's index.

In the update function below (which is just part of
the entire function) the function displays garbage
as before (even with changes I made from suggestions
from the group) after I enter the email address.

The function though continues and prompts "is this
is the record I want to display".

If I enter 'Y' the cursor goes to the next line but
does not enter any prompts. If I hit enter 6 more
times I get the prompt "Do you want to update any
more records?Y/N" This functions correctly whether
or not I hit 'Y' or 'N'.

If I enter 'N' I get the prompt " Do you want
to change the last name?" If I enter 'N' it
proceeds to the next prompt " Do you want
to change the first name" I repeat this to
the prompt on phone. After phone the prompt
"Do you want to change email address appears
but the cursor goes to the next prompt " Do
you want to update another record". The same
behavior is elicited as it was above if 'Y' is
entered. But the return key has to be pressed
2 fewer times for each prompt.

Since this program uses the find function I placed
it under the update function. see comments below

Any suggestions would be appreciated.

Thanx in advance

Alan

void update_record ( PERSON update_record [ ], int update )

{

        int found;
        update = 0;
        int mode = UPDATE;
        int funct = UPDATE;

do {

printf ("Please enter an email address \n\n  ");

gets ( update_record [update] . email );

found = find_record ( update_record, MAX_RECORDS, update, funct );
        /* At this point I get garbage*/

printf ( "Do you want to change the last name? YES/NO ");

if (getchar == 'Y' )

/* If I enter 'Y' the cursor goes to next line and I press enter 6 times it goes to update another record prompt*/

{

printf ( "Enter a new last name" );

gets ( update_record [update] . lname);

strcpy ( update_record [found] . lname,

update_record [update] . lname);

                                                        }

else
        If ( getchar ( )  == 'N' )

/* If I enter 'N' at the rest of the prompts the program runs as it should until email (see below)*/

printf ( "Do you want to change the first name? YES/NO");

if ( getchar ( ) == 'Y' )

{
printf ( "Enter a new first name" );

gets ( update_record [update] . fname);

strcpy ( update_record [found] . fname, update_record [update] .fname);
                                }                                                                      

Quote:
}

/* This function continues as above and prompts for last name, address, phone number and email
address. When it gets to email address it displays the prompt but the cursor goes to the next prompt
which is update record.*/

update ++;

printf ( "Do you want to update another record? Y/N");

                }while ( getchar ( ) =='Y');

Quote:
}

Here is the find record function:

int find_record ( PERSON find_record [ ], int update, int funct )

{

int counter = 0;

FILE *fptr;

if ((fptr = fopen("records.dbf","rb")) == NULL)

{
printf ("No database file found");

exit (1);

Quote:
}

while ( counter != MAX_RECORDS)
{
if  ( strcmp ( find_record [update] . email, find_record [counter] . email ) == 0)
{
while ( fread ( &find_record [update], sizeof (find_record [update]),1, fptr ) == 1)
{
printf ( "%s\n", find_record [update] . lname );
printf ( "%s\n", find_record [update] . fname );
printf ( "%s\n", find_record [update] . address );
printf ( "%s\n", find_record [update] . phone );
printf ( "%s\n", find_record [update] . email );

 }

switch ( funct )
 {
case DISPLAY : puts ( "Is this the record you want to display? Y/N?...");

break;

 case DELETE :  puts ("Is this the record you want to delete? Y/N?...");

break;

case    UPDATE :  puts ( "Is this the record you want to update? Y/N/...");

break;

default : printf ("Invalid function call %d", funct);

break;

 }
 }
counter++;

 }

fclose ( fptr );

if ( getchar() == 'Y' )

return counter;

else

return -1;

Quote:
}



Wed, 09 Apr 2003 12:39:24 GMT  
 Need Help Executing Program (suggestions from group added but not quite there yet)

Quote:

<snip>

> Any suggestions would be appreciated.

Given the title line, you've already shown this code to comp.lang.c at
least once.

Since that's the case, I doubt whether you're likely to get much
sympathy here for your difficulty until you get rid of the gets() calls
and replace them with fgets(). The gets() function has no place in any C
program. It's a bug waiting to happen.

--
Richard Heathfield
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
66 K&R Answers: http://users.powernet.co.uk/eton/kandr2/index.html (31
to go)



Wed, 09 Apr 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Need some suggestion, hope programmers help(NOT a VC++ problem)

2. I am not quite understand the program asks for

3. I am not quite understand the program asks for

4. Need Suggestion / help for window programming in c

5. Need help with adding enhancements to program

6. HELP : EXECUTE a .exe program within a c or c++ program

7. Add a domain Group/User to a local computer group

8. Can I use CRecordset to execute StoredProcs, which do not return a rowset, but need parameters

9. Functions of Program do not execute properly

10. How (not) to Program in C (was Re: PD C as solution to binary groups)

11. need help: why does my program not work?

12. How can I execute a program with activeX not registered in the target computer

 

 
Powered by phpBB® Forum Software