Like Tree1Likes
  • 1 Post By claudiu

pointers and function definitions.

This is a discussion on pointers and function definitions. within the C Programming forums, part of the General Programming Boards category; Hi guys I'm wondering why I use * before define a function ? For example Code: char * strcopy (char ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    46

    pointers and function definitions.

    Hi guys I'm wondering why I use * before define a function ?
    For example

    Code:
    char *strcopy(char *copy,char *original) { /* Why ı can not use just strcopy instead of *strcopy????*/ for(int k=0;(*copy++ = *original++)!='\0';) k++; return copy ; }


    ıs there anyone who can help me please ?
    Last edited by dayanike; 04-24-2012 at 10:15 AM.

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    We would if we could see the code you are referring to.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    46
    Sorry I've just edited it .

  4. #4
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Ahh, the little '*' there belongs to the return value not to the function name. Unfortunately the following is equivalent in C:

    char* myFunc(void)

    AND

    char *myFunc(void)

    hence your little confusion.
    dayanike likes this.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  5. #5
    Registered User
    Join Date
    Feb 2012
    Posts
    46
    thanks a lot for your quick answer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 23
    Last Post: 03-07-2011, 05:28 PM
  2. Function Definitions with Iterators
    By pianorain in forum C++ Programming
    Replies: 5
    Last Post: 05-17-2010, 03:58 PM
  3. Function definitions
    By lifeis2evil in forum C++ Programming
    Replies: 21
    Last Post: 11-03-2007, 07:57 PM
  4. help writing function definitions
    By jlmac2001 in forum C++ Programming
    Replies: 2
    Last Post: 04-10-2003, 10:44 PM
  5. Function Definitions
    By PutoAmo in forum C Programming
    Replies: 4
    Last Post: 03-03-2002, 06:24 PM

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