stuck with conflicting types for

This is a discussion on stuck with conflicting types for within the C Programming forums, part of the General Programming Boards category; when i compile the code i get this error strlen.c:4:5: error: conflicting types for ‘strlen’ strlen.c:13:5: error: conflicting types for ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    26

    stuck with conflicting types for

    when i compile the code i get this error


    strlen.c:4:5: error: conflicting types for ‘strlen’
    strlen.c:13:5: error: conflicting types for ‘strlen’


    /////////////////////////////////////////////////////////////////
    this my code
    /////////////////////////////////////////////////////////////////
    Code:
    #include <stdio.h>
    #include <string.h>
    
    int strlen(char *);
    
    
    int main()
    {
    strlen("rukshan");
    printf("%d\n",strlen("rukshan"));
    }
    
    
    /* strlen: return length of string s */
    int strlen(char *s)
    {
          int n;
          for (n = 0; *s != '\0';s++)
          n++;
         return n;
    }
    plz help meeeee............
    thank you

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,338
    Well it's also the name of a function in string.h (which you include).

    Either
    - don't use ANY standard string functions, by omitting string.h
    - (better) call it something else, like my_strlen()
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    26
    hei thank you soooo much .i fixed it out

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Also note that line 9 has no effect since you are ignoring the return value.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Conflicting types error
    By mastrxplodr in forum C Programming
    Replies: 4
    Last Post: 04-12-2011, 11:56 AM
  2. Conflicting Types for function
    By tomeatworld in forum C Programming
    Replies: 1
    Last Post: 12-06-2010, 10:43 AM
  3. Conflicting types???
    By kwikness in forum C Programming
    Replies: 11
    Last Post: 10-07-2007, 11:53 PM
  4. error: conflicting types
    By Rodman in forum C Programming
    Replies: 5
    Last Post: 03-10-2006, 03:20 AM
  5. conflicting types for...
    By dudinka in forum C Programming
    Replies: 3
    Last Post: 05-14-2005, 07:03 AM

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