please help with this program 
Author Message
 please help with this program

I don't understand this program. I wrote it a month ago and it ran
fine. I either #1 changed it and forgot what I did (now I see the
importance of documentation) #2 have lost my mind and can't see a
simple problem or #3 compiled it on an AIX and now it won't compile on
BC++ 5.0. It keeps giving me the same error at the line noted by

Quote:
>>>>>>>>>>>>><<<<<<<<<<<<<<<<<< below.

The error says:

Error:  parts_db.cpp(67,12):Cannot convert 'void *' to Appt *'

Here is the program: Thanks for any suggestions!
Ryan
---------------------------------------------------------------------------------------------------------------
/* Maintains a little appointent schedule (linked list version) */

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

#define NAME_LEN 25
#define PROB_LEN 50

struct Appt {
   int time; /* This is the search criteria */
   char name[NAME_LEN+1];
   char problem[PROB_LEN+1];
   struct Appt *next;
   };

struct Appt *inventory = NULL; /* points to first Appt */

struct Appt *find_Appt(int time);
void insert(void);
void search(void);
void del_node(void);
void print(void);

main()
{
        char code;
        int i;
        for (;;) {
          printf("\t(I)nsert\n\t(S)earch\n\t(D)elete\n\t(P)rint\n\t(Q)uit\n");
          printf("\nEnter Selection: ");
          scanf(" %c", &code);
          while (getchar() != '\n') /* skips to end of line */
           ;
         switch (code) {
           case 'i': insert();
                     break;
           case 's': search();
                     break;
           case 'd': del_node();
                     break;
           case 'p': print();
                     break;
           case 'q': return 0;
           default: printf("\nNot a valid entry\n");
           }
        printf("\n");
       }

Quote:
}

struct Appt *find_Appt(int time)
{
        struct Appt *p;

        for (p = inventory;
             p != NULL && time > p->time;
             p = p->next)
             ;
        if (p != NULL && time == p->time)
            return p;
            return NULL;

Quote:
}

void insert(void)
{
        struct Appt *cur, *prev, *new_node;

        new_node = malloc (sizeof(struct Appt));
        if (new_node == NULL) {
           printf("Database full, no entry");
           return;
        }

        printf("Enter time for appt in MILITARY FORMAT: ");
          scanf("%d", &new_node->time);

        for (cur = inventory, prev = NULL;
             cur != NULL && new_node->time > cur->time;
             prev = cur, cur = cur->next);

        if (cur != NULL && new_node->time == cur->time) {
             printf("Appt already scheduled for that time!\n");
             free(new_node);
             return;
        }

        printf("Enter patient name: ");
        scanf("%s", &new_node->name);
        printf("Enter patient problem: ");
        scanf("%s", &new_node->problem);

        new_node -> next=cur;
        if (prev == NULL)
          inventory = new_node;
        else
          prev->next = new_node;

Quote:
}

void search(void)
{
       int time;
        struct Appt *p;
        printf("Enter Appt Time: ");
        scanf("%d", &time);
        p=find_Appt(time);
        if (p != NULL) {
                printf("Patient Name: %s\n", p->name);
                printf("Problem: %s\n", p->problem);
        } else
          printf("Appt not found.\n");

Quote:
}

void del_node(void)
{
        int time, change;
        struct Appt *p;

        printf("Enter Appt Time: ");
        scanf("%d", &time);
        p = find_Appt(time);
        if (p != NULL) {
                printf("This is going to be delete look at old code for this func");
        } else
          printf("Appt not found\n");

Quote:
}

void print(void)
{
        struct Appt *p;
        printf("\nAppt Time\t\tName\t\tProblem\n");
        for (p = inventory; p != NULL; p = p->next)
        printf("%d\t\t%s\t\t%s\n", p->time, p->name, p->problem);
Quote:
}



Fri, 29 Oct 1999 03:00:00 GMT  
 please help with this program

Quote:

>The error says:

>Error:  parts_db.cpp(67,12):Cannot convert 'void *' to Appt *'
>        struct Appt *cur, *prev, *new_node;

>        new_node = malloc (sizeof(struct Appt));

If this is the line in question, modify it to read

        new_node = (Appt *)malloc (sizeof(struct Appt));

Lasse

---------------------------
Lasse V?gsther Karlsen

http://home.sol.no/lassevk/
---------------------------



Sat, 30 Oct 1999 03:00:00 GMT  
 please help with this program


Quote:

>>The error says:

>>Error:  parts_db.cpp(67,12):Cannot convert 'void *' to Appt *'
>>        struct Appt *cur, *prev, *new_node;

>>        new_node = malloc (sizeof(struct Appt));
>If this is the line in question, modify it to read
>        new_node = (Appt *)malloc (sizeof(struct Appt));

If a compiler accepts the second version, but not the first, it is
not a C compiler. It may be a C++ compiler that is not in C mode
at the moment, but might be tricked into accepting C code with
a minor effort, like, e.g., setting the appropriate command line
switch, or using the right file extention, or giving the file the
correct extended attribute.

See the documentation of your implementation for details.

Kurt

--
| Kurt Watzka                             Phone : +49-89-2180-6254



Sat, 30 Oct 1999 03:00:00 GMT  
 please help with this program

Quote:

>I don't understand this program. I wrote it a month ago and it ran
>fine. I either #1 changed it and forgot what I did (now I see the
>importance of documentation) #2 have lost my mind and can't see a
>simple problem or #3 compiled it on an AIX and now it won't compile on
>BC++ 5.0. It keeps giving me the same error at the line noted by
>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<< below.

>The error says:

>Error:  parts_db.cpp(67,12):Cannot convert 'void *' to Appt *'

You aren't using a C compiler. The .cpp extension suggests C++. Always
compile a program with a compiler for the language it is written in, for
C code use a C compiler for C++ code use a C++ compiler. It should be
possible to invoke your BC++ system as a C compiler, check your
documentation for how to do it.

--
-----------------------------------------


-----------------------------------------



Sat, 30 Oct 1999 03:00:00 GMT  
 please help with this program


Quote:
(Lasse V?gs?ther Karlsen) writes:

>> The error says:
>> Error:  parts_db.cpp(67,12):Cannot convert 'void *' to Appt *'
>>        struct Appt *cur, *prev, *new_node;
>>        new_node = malloc (sizeof(struct Appt));

> If this is the line in question, modify it to read
>         new_node = (Appt *)malloc (sizeof(struct Appt));

If the code and error message were really as stated, a better
solution would be to get a C compiler.  (It sounds as if Ryan may
be using a C++ compiler.)  If malloc() is correctly declared as
returning void * (as the error message strongly implies that it
is), then the lines

        struct Appt *new_node;
        new_node = malloc (sizeof(struct Appt));

are 100% correct, and a C compiler has no reason to complain.
(In particular, the whole point of the void * type is that it
*is* possible to (implicitly) convert a void * value into any
other type of object pointer, including struct Appt *.
I hear, though, that the situation is different in C++.)

[Oh.  Duh.  "parts_db.cpp".  I guess another better solution
would be to post the question to comp.lang.c++, then.  I guess
I don't even need to post this followup, since my clue about
parts_db.cpp came from the followup I just noticed that Lawrence
Kirby posted already.]

                                        Steve Summit



Sun, 31 Oct 1999 03:00:00 GMT  
 please help with this program

Groovy hepcat Lasse V?gs?ther Karlsen was jivin' on Tue, 13 May 1997
09:19:13 GMT in comp.lang.c.
Re: please help with this program's a cool scene! Dig it!

Quote:
>>Error:  parts_db.cpp(67,12):Cannot convert 'void *' to Appt *'
>>        struct Appt *cur, *prev, *new_node;
>>        new_node = malloc (sizeof(struct Appt));
>If this is the line in question, modify it to read
>        new_node = (Appt *)malloc (sizeof(struct Appt));

                    ^^^^^^^^
  That should be (struct Appt *), should it not?

----- Dig the EVEN NEWER, MORE IMPROVED news sig!! -----

-------------- Shaggy was here! ---------------
    http://aardvark.apana.org.au/~phaywood/
============= Ain't I'm a dawg!! ==============



Sun, 28 Nov 1999 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. please help with this program

2. PLEASE help UDP client programming

3. please help with this program

4. Please Help With C Program

5. Please help with C program

6. Please help beginner with programming problem

7. Please Help with this program

8. Oh gurus, please help getting VC program into DLL

9. Please help S3- card programming under TC?

10. Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!

11. Please help, question about programming in C to access COM1/COM2 in my FreeBSD.

12. Please help!!!!Please help!!!!Please help!!!!

 

 
Powered by phpBB® Forum Software