incompatible pointer types

This is a discussion on incompatible pointer types within the C Programming forums, part of the General Programming Boards category; i keep getting incompatible pointer types when i try to compile this Code: int isascii(int *src) { if( ishtml(src) == ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    913

    incompatible pointer types

    i keep getting incompatible pointer types when i try to compile this

    Code:
    int isascii(int *src) {
        if( ishtml(src) == 0 )
            return 1;
    
        return 0;
    }
    
    int ishtml(char *src) {
        if( ishtmlkeycode(src) == 1 && ishtmltag(src) == 1 )
            return 1;
    
        return 0;
    }
    i tried adding a "&", didnt help. whats the probelm here?

  2. #2
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323

    Re: incompatible pointer types

    Originally posted by mart_man00
    Code:
    int isascii(int *src) {
        if( ishtml(src) == 0 )
            return 1;
    
        return 0;
    }
    
    int ishtml(char *src) {
        if( ishtmlkeycode(src) == 1 && ishtmltag(src) == 1 )
            return 1;
    
        return 0;
    }
    You are creating a pointer in isascii() of type int and then passing it, but the next function ishtml() is trying to receive a pointer to char data type. One of those needs to be changed.
    The keyboard is the standard device used to cause computer errors!

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    913
    i thought the only difference in types were there sizes and pointer just point to a start of data(not necessarily something[0] but not something[.5]).

    how can it tell the difference? how are types allocated?

    thanks

  4. #4
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323
    Think of it as the pointer needs to know what it is pointing to so it knows how many byts to look at. For char its 1 byte, for integer, on most systems its 4 bytes. You are right in that fact that a pointer points to the beginning byte location, but its needs to know how big the data type is so it also knows where the second and third element locations are later on.
    The keyboard is the standard device used to cause computer errors!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Incompatible types in assignment.
    By killpoppop in forum C Programming
    Replies: 36
    Last Post: 12-22-2008, 11:08 AM
  2. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of Cprogramming.com
    Replies: 48
    Last Post: 05-10-2007, 02:25 AM
  3. Pointer types
    By jrfall349 in forum C Programming
    Replies: 8
    Last Post: 04-23-2007, 10:58 PM
  4. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 01:19 AM
  5. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21