Thread: incompatible types in assignment

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    78

    incompatible types in assignment

    Why might this be: incompatible types in assignment

    Here is my struct:

    Code:
    typedef struct{
    char name[250];
    char number[10];
    } List;
    Here is the error:

    Code:
    char input[250];
    List *new=(List *)malloc(sizeof(List));
    
    
    		printf("\n\nEnter Name: ");
    			fgets(input, 250, stdin);
        				if ((p = strchr(input, '\n')) != NULL)
          				*p = '\0';
    			new->name=input;     //<---------ERROR

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    78
    Oh, I think I know...

    I need:

    strcpy(new->name, input);



  3. #3
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Also, don't forget to check the your call from malloc to ensure it worked successfully. Plus a little FAQ reading on malloc
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. incompatible types in assignment
    By davidjg in forum C Programming
    Replies: 3
    Last Post: 04-08-2011, 03:30 PM
  2. incompatible types in assignment
    By sergioms in forum C Programming
    Replies: 3
    Last Post: 03-24-2011, 11:30 AM
  3. Incompatible types in assignment.
    By killpoppop in forum C Programming
    Replies: 36
    Last Post: 12-22-2008, 12:08 PM
  4. incompatible types in assignment
    By vapanchamukhi in forum C Programming
    Replies: 1
    Last Post: 09-18-2008, 11:35 PM
  5. Incompatible types in assignment
    By Taka in forum C Programming
    Replies: 4
    Last Post: 10-17-2006, 05:33 AM