Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

incompatible types error? :-(

incompatible types error? :-(

incompatible types error? :-(

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? :(

RE: incompatible types error? :-(

This sounds familiar for some reason.  winky smile

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:


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?

RE: incompatible types error? :-(

From what you've said, findEvent is something like


char* findEvent(const char*)
So what you're doing is


struct{char[], int) = char*
That is why it is incompatible.  If findEvent is defined as


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


void findEvent (const char*, Event*);
findEvent (temp, &node->e.event);
Doesn't look as neat but it will get round the stack problems.

RE: incompatible types error? :-(

Okie... I fixed it :)
Thanx a bunch guys!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close