error: incompatible types in asignment

Discussion in 'C Programming' started by Dennis Schulz, May 26, 2004.

  1. Hi all,

    the following programm is supposed to check for login and password
    with inbuilt linux functions. in line 57 and 64 there are erorrs:
    incompatible types in asignment. whats wrong with this? the crypt
    function returns a pointer to a char. why an assignment to a char
    vector is not possible?

    MfG Dennis




    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #define _XOPEN_SOURCE


    #include <assert.h>
    #include "auth.h"
    #include <unistd.h>
    #include <sys/types.h>
    #include <pwd.h>
    #include <shadow.h>
    #include <unistd.h>

    int main() {

    struct passwd *pw;
    struct spwd *spw;

    char temp[4];
    char user[20];
    char pass[20];
    char encryptedinput[20];
    char encryptedpw[30];
    char salta[12];
    char saltb[2];

    printf("%s", "User: ");
    scanf("%s", &user);
    printf("\n\n");
    printf("%s", "Passwort: ");
    scanf("%s", &pass);
    printf("\n\n");
    // prueft ob user vorhanden
    if( ( pw = getpwnam( user ) ) == NULL ) {
    fprintf( stderr, "getpwnam: unknown %s\n",user );
    exit( EXIT_FAILURE );
    }
    // pruefe ob superuser
    if (strcmp(pw->pw_passwd, "x") == 0) {
    if( ( spw = getspnam( user ) ) == NULL ) {
    fprintf( stderr, "getspnam: unknown %s\n",user );
    exit( EXIT_FAILURE );
    }
    strcpy(encryptedpw,spw->sp_pwdp);
    // wenn kein superuser
    } else {
    strcpy(encryptedpw,pw->pw_passwd);
    }
    // hole erste drei zeichen
    strncpy(temp,encryptedpw,3);
    temp[3]='\0';
    if ((strcmp(temp,"$1$"))==0) {
    strncpy(salta,encryptedpw,12);
    salta[12]='\0';
    if( ( encryptedinput = crypt( pass, salta ) ) == NULL ) {
    fprintf( stderr, "Fehler beim verschluesseln");
    exit( EXIT_FAILURE );
    }
    } else {
    strncpy(saltb,encryptedpw,2);
    saltb[2]='\0';
    if( ( encryptedinput = crypt( pass, saltb ) ) == NULL ) {
    fprintf( stderr, "Fehler beim verschluesseln");
    exit( EXIT_FAILURE );
    }
    }
    // verschluessle passwort

    if (strcmp(encryptedinput, encryptedpw) == 0) {
    printf("%s\n\n","LOGIN ERFOLGREICH!!!");
    } else {
    printf("%s\n\n","LOGIN FEHLGESCHLAGEN!!!");
    }
    exit( EXIT_SUCCESS );
    }
    Dennis Schulz, May 26, 2004
    #1
    1. Advertising

  2. Dennis Schulz

    Eric Sosman Guest

    Dennis Schulz wrote:
    > Hi all,
    >
    > the following programm is supposed to check for login and password
    > with inbuilt linux functions. in line 57 and 64 there are erorrs:
    > incompatible types in asignment. whats wrong with this? the crypt
    > function returns a pointer to a char. why an assignment to a char
    > vector is not possible?


    Arrays are not assignable in C.

    > char encryptedinput[20];


    This should probably be `char *encryptedinput;'.

    > [...]
    > if( ( encryptedinput = crypt( pass, salta ) ) == NULL ) {


    If you do not understand the difference between an array
    and a pointer, please see Question 6.8 -- in fact, all of
    Section 6 -- in the comp.lang.c Frequently Asked Questions
    (FAQ) list at

    http://www.eskimo.com/~scs/C-faq/top.html

    --
    Eric Sosman, May 26, 2004
    #2
    1. Advertising

  3. Emmanuel Delahaye, May 26, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raptor

    asignment in class

    Raptor, Mar 3, 2005, in forum: C++
    Replies:
    1
    Views:
    321
    Tim Slattery
    Mar 3, 2005
  2. Raptor

    asignment in class

    Raptor, Mar 3, 2005, in forum: C++
    Replies:
    3
    Views:
    4,632
    Bill97
    Mar 20, 2005
  3. Simon Mansfield

    Linked list's asignment help..

    Simon Mansfield, Dec 7, 2004, in forum: C Programming
    Replies:
    5
    Views:
    298
    Richard Bos
    Dec 8, 2004
  4. Replies:
    3
    Views:
    808
  5. viki
    Replies:
    4
    Views:
    271
    Juha Nieminen
    Apr 17, 2008
Loading...

Share This Page