Thread: incompatible types in assignment

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    9

    incompatible types in assignment

    (My third thread today :P)
    well now i have the title's error in a part of my code like this
    Code:
    if((strcmp(new_account->description_nametraveller,sm_data->description_nametraveller)) ==0){
                      ipoloipo = sm_data->price_logariasmos;
                      onoma = sm_data->description_nametraveller;
    where sm_data is a pointer to shared memory and in onoma i want to save the value of description_nametraveller

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    There are two assignment statements in your code snippet, so investigate the types of the variables involved
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    9
    both onoma and price_logariasmos are integers..

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Good to hear, except that sm_data->description_nametraveller is probably an array of char or a pointer to char, and perhaps ipoloipo is something other than an integer too.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    9
    sry i'm so comfused after so many hours of writing..the problem is in the line onoma = sm_data->description_nametraveller;
    and both onoma and description_nametraveller ara char[80].. it's strange that i'm getting this error..

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well if both are char arrays, then you need to use strcpy() to copy them.
    You can't assign one array to another.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Nov 2011
    Posts
    29
    so you're saying description_nametraveller is a char array and onoma is an integer?
    Why the assignment then?

  8. #8
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by naturegirl View Post
    so you're saying description_nametraveller is a char array and onoma is an integer?
    No, evidently that was a mistake:

    Quote Originally Posted by tetartos View Post
    sry i'm so comfused after so many hours of writing..the problem is in the line onoma = sm_data->description_nametraveller;
    and both onoma and description_nametraveller ara char[80].. it's strange that i'm getting this error..
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  9. #9
    Registered User
    Join Date
    Nov 2011
    Posts
    29
    ok, guess I can't read =_=

  10. #10
    Registered User
    Join Date
    Nov 2011
    Posts
    9
    strcpy did the job.ty

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: 6
    Last Post: 09-19-2008, 07:45 AM
  5. incompatible types in assignment
    By vapanchamukhi in forum C Programming
    Replies: 1
    Last Post: 09-18-2008, 11:35 PM