Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

incompatible types error? :-(

Status
Not open for further replies.

NatMinx

Programmer
Jun 24, 2008
10
CA
/////Declarations/////
typedef struct event_t {
char event[100];
int year;
} Event;

struct CalendarNode {
Event e;
struct CalendarNode *next;
};
/////////////////////////////

I'm getting an error from this line of code:

node->e.event = findEvent(temp);

where node points to the calendar node list [struct CalendarNode *list], e is the event of node, and event is in the form "EVENT:CSC209 Lecture" string in struct e, findEvent is a function that takes char *string as param and returns a pointer to char.


The error I'm getting is:

error: incompatible types in assignment


What am I doing wrong? :(
 
This sounds familiar for some reason. ;-)

You can't copy strings (i.e. char arrays) like that, you can only copy pointers & value types.
Pass e into findEvent() and use strncpy()... Something like this:
Code:
void findEvent( Event* e, const char* temp )
{
   strncpy( e->event, temp, sizeof( e->event ) );
}
I'm not sure what you're doing with the temp variable, so I'm assuming you're copying that string into your Event?
 
From what you've said, findEvent is something like
Code:
char* findEvent(const char*)
So what you're doing is
Code:
struct{char[], int) = char*
That is why it is incompatible. If findEvent is defined as
Code:
Event findEvent(const char*)
then it won't be a problem but you may get stack problems at a later date. The best way to do it is to change findEvent to
Code:
void findEvent (const char*, Event*);
...
findEvent (temp, &node->e.event);
Doesn't look as neat but it will get round the stack problems.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top