Incompatible types in assignment

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Benga89
    New Member
    • Jul 2010
    • 1

    Incompatible types in assignment

    Hi!

    I'm currently working on a small program that prints records
    of a database.

    However during compilation I'm getting an error: "Incompatib le types in assignment".

    I'm al ittle bit stuck for the moment. If anyone could help me out that would be great!!

    Thanks in Advance!!

    The small program is as following:

    Code:
    #include <stdio.h>
    #include <string.h>
    
    typedef struct record {
    char Naam[25];
    char Adres[25];
    int Tel[10];
    }Record; 
    
    struct database{
    Record record1 ;
    Record record2;
    Record record3;
    Record record4;
    Record record5;       
    } db0;
    
    
    void Print (Record *data);
    
    main (void) 
    {
    /*Statische initialisatie van database */
    
    db0.record1.Naam = "Peeters";/* here i get the error!!*/
    db0.record1.Adres = "Langendries 5"; /*and here*/
    db0.record1.Tel = 25428956;/*and here*/
    
    db0.record2.Naam = "Van Damme";/*and here*/
    db0.record2.Adres = "Poststraat 9";/*and here*/
    db0.record2.Tel = 56898569 ;/*and here*/
    
    db0.record3.Naam = "Martens";/*and here*/
    db0.record3.Adres = "Akkerstraat 56";/*and here*/
    db0.record3.Tel = 5689745 ;/*and here*/
    
    db0.record4.Naam = "Neeskens";/*and here*/
    db0.record4.Adres = "Azalealaan 12";/*and here*/
    db0.record4.Tel = 168235689 ;/*and here*/
    
    db0.record5.Naam = "Goovaerts";/*and here*/
    db0.record5.Adres = "Dorpstraat 4";/*and here*/
    db0.record5.Tel = 165894556 ;/*and here*/
    
    DrukAf(&db0.record1);
    DrukAf(&db0.record2);
    DrukAf(&db0.record3);
    DrukAf(&db0.record4);
    DrukAf(&db0.record5);
    for(;;){};
    
      
    }
    void Print (Record *data) {
    printf("Naam: %25s \n",data->Naam);
    printf("Adres: %25s \n",data->Adres);
    printf("Telefoonnummer: %10d \n",&data->Tel);     
    }
    Last edited by Banfa; Jul 21 '10, 06:38 PM. Reason: Added [code] ... [/code] tags
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Taking this

    db0.record1.Naa m = "Peeters";/* here i get the error!!*/

    as an example

    db0.record1.Naa m has type char[25] an array of 25 char; "Peeters" has the type const char *, a pointer to constant char. These types are not compatible for assignment.

    In fact in C/C++ you can not assign to any array. You need to use the strcpy function from strings.h.

    Comment

    Working...