Thread: Why do I need to cast to char* here?

  1. #1
    Old Fashioned
    Join Date
    Nov 2016
    Posts
    137

    Question Why do I need to cast to char* here?

    I'm at a loss of words as to why this won't compile:

    char *result = piglatin("Amanda");

    but this will (and works fine):

    char *result = (char*)piglatin("Amanda");

    When the func sig for piglatin() is:

    char *piglatin(char *str)

    GCC says: " warning: initialization makes pointer from integer without a cast"

    Anyone know why this is? I'm either very tired or something strange is going on because the func already returns a char* so not sure why I need cast there. Thanks.
    Last edited by Asymptotic; 04-10-2018 at 02:59 AM.
    If I was homeless and jobless, I would take my laptop to a wifi source and write C for fun all day. It's the same thing I enjoy now!

  2. #2
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Are you sure there is a function prototype for the function that appears before you use the function?

  3. #3
    Registered User
    Join Date
    Apr 2017
    Location
    Quetzaltenango
    Posts
    82
    Did you forget a semicolon on your function prototype?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cast an int to char
    By tinchi in forum C Programming
    Replies: 8
    Last Post: 10-03-2014, 01:48 AM
  2. Cast to char from int
    By TeeGee in forum C Programming
    Replies: 6
    Last Post: 02-23-2010, 02:02 AM
  3. cast unsigned char* to (the default) signed char*
    By Mario F. in forum C++ Programming
    Replies: 24
    Last Post: 07-27-2007, 10:41 AM
  4. how to cast a char to an int
    By rozner in forum C Programming
    Replies: 2
    Last Post: 03-27-2003, 03:50 PM
  5. How do I cast a char Array[] to a const char* ?
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 10-13-2001, 08:43 AM

Tags for this Thread