1. Post #1
    I'm a tool
    KillerLUA's Avatar
    June 2009
    1,332 Posts
    I'm very, very new to C but not to programming languages so I've managed to piece together some basic code. I'm going to assume that it's possible to compile something without warnings, does anybody know how to deal with

    Code:
    warning: implicit declaration of function `strcpy`
    warning: incompatible implicit declaration of built-in function `strcpy`
    warning: implicit declaration of function `strcat`
    warning: incompatible implicit declaration of built-in function `strcat`
    main.c:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #include "ace_main.h"
    
    int main() {
         msg "Test Message!");
         return 0;
    }
    ace_main.h:
    Code:
    void msg(const char* msg) {
         char str[128];
    
         strcpy(str, msg);
         strcat(str, "\n");
    
         printf(str);
    }
    I'm compiling on linux using gcc.

  2. Post #2
    Kamshak's Avatar
    July 2008
    417 Posts
    idk if this is the cause but
    msg "Test Message!");
    msg( "Test Message!");

  3. Post #3
    I'm a tool
    KillerLUA's Avatar
    June 2009
    1,332 Posts
    I'll try, thanks

    Edited:

    That was just a typo I made when copying it over, since the machine I'm using to compile is Linux and separate to my current windows machine.

  4. Post #4
    Liquid Helium's Avatar
    October 2010
    113 Posts
    your missing:
    Code:
    #include <string.h>
    also, it's probably better to just do
    Code:
    void msg(const char* msg) {
         printf("%s\n", msg);
    }

  5. Post #5
    I'm a tool
    KillerLUA's Avatar
    June 2009
    1,332 Posts
    Thanks

  6. Post #6
    Gold Member
    Jookia's Avatar
    July 2007
    6,768 Posts
    Also, use strncpy. Otherwise you'll get a buffer overflow and fuck shit up.
    Reply With Quote Edit / Delete Reply Linux Australia Show Events Agree Agree x 1 (list)

  7. Post #7
    Never declare functions in headers, declare only their prototypes in headers if you want to share functions between code files, and write code of functions only in code files.
    Reply With Quote Edit / Delete Reply Windows 8 Russian Federation Show Events Agree Agree x 6 (list)

  8. Post #8
    DarkCarnage's Avatar
    May 2009
    108 Posts
    Never declare functions in headers, declare only their prototypes in headers if you want to share functions between code files, and write code of functions only in code files.
    this->goodAdvice, oh wait
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Dumb Dumb x 7 (list)