• Quick C Question
    7 replies, posted
  • 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` [/CODE] [B]main.c:[/B] [CODE] #include <stdio.h> #include <stdlib.h> #include "ace_main.h" int main() { msg "Test Message!"); return 0; } [/CODE] [B]ace_main.h[/B]: [CODE] void msg(const char* msg) { char str[128]; strcpy(str, msg); strcat(str, "\n"); printf(str); } [/CODE] I'm compiling on linux using [B]gcc[/B].
  • Avatar of Kamshak
  • idk if this is the cause but msg "Test Message!"); msg( "Test Message!");
  • I'll try, thanks [editline]10th June 2012[/editline] 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.
  • Avatar of Liquid Helium
  • your missing: [code]#include <string.h>[/code] also, it's probably better to just do [code] void msg(const char* msg) { printf("%s\n", msg); } [/code]
  • Avatar of Jookia
  • Also, use strncpy. Otherwise you'll get a buffer overflow and [b]fuck shit up[/b].
  • Avatar of SiPlus
  • 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.
  • Avatar of DarkCarnage
  • [quote]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.[/quote] this->goodAdvice, oh wait :suicide: