Thread: implicit declaration of function?

  1. #1
    Brak BoneXXX's Avatar
    Join Date
    Mar 2007
    Location
    Bangkok
    Posts
    62

    implicit declaration of function?

    Code:
    warning: implicit declaration of function `malloc'
    warning: implicit declaration of function `strlen'
    warning: implicit declaration of function `strcpy'
    I am getting these messages when I compile my files with: gcc -Wall -ansi -pedantic -O *.c.
    But if I compile with just gcc *.c the program compiles fine and works fine.

    the lines that cause the message are:
    Code:
    p=(char*)malloc(strlen(buffer)+1);
    strcpy(p,buffer);
    Could you tell me what is wrong and what is the right way to do it? Thanks in advance.
    “Example isn't another way to teach, it is the only way to teach” Albert Einstein

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    You need to include the appropriate headers. In this case, stdlib.h and string.h

  3. #3
    Brak BoneXXX's Avatar
    Join Date
    Mar 2007
    Location
    Bangkok
    Posts
    62
    Thanks a lot, it is a simple thing but when you don't have much experience, it is a complex problem. I was trying to figure out for hours. I appreciate it, it compiles fine now.
    Last edited by BoneXXX; 04-27-2007 at 11:41 PM.
    “Example isn't another way to teach, it is the only way to teach” Albert Einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Replies: 15
    Last Post: 11-11-2007, 10:40 AM
  3. Implicit declaration of function : wait()
    By husust in forum C Programming
    Replies: 2
    Last Post: 02-06-2006, 09:35 AM
  4. cannot start a parameter declaration
    By Dark Nemesis in forum C++ Programming
    Replies: 6
    Last Post: 09-23-2005, 02:09 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM