#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    27
    Rep Power
    0

    Type mismatch in redeclaration of function display


    #include<stdio.h>
    #include<conio.h>

    void main()
    {

    char string[] ="hello string";
    display(string);

    }

    void display(*string)
    {
    printf("%s",string);
    }
    if we compile the above program we get the above error
    if i want to overcome the above error what changes i need to do

    first i thought of declaring the function
    line void display(char *)
    but itz all vain
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,379
    Rep Power
    1871
    1. Use [code][/code] tags when posting code.

    2. main returns int, not void

    3. Stop using conio.h. It is an obsolete DOS header file. Unless you're still using TurboC (another don't), you should be using things appropriate to this millennium.

    4. Prototype the function above main(). In fact, anywhere before the first use.
    Like so
    Code:
    void display ( char *string );
    int main()
    {
        char string[] ="hello string";
        display(string);
        return 0;
    }
    
    void display(char *string)
    {
        printf("%s",string);
    }

    Comments on this post

    • Technovicez agrees
    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
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    27
    Rep Power
    0
    thankz a ton :)

IMN logo majestic logo threadwatch logo seochat tools logo