I’m trying to code an IRC bot. The bot connects to the server, however I can’t get it to join a channel.
int conn;
char sbuf[512];
// Function I'm trying to use
void join(char *fmt, ...){
va_list ap;
va_start(ap,fmt);
vsnprintf(sbuf,512, fmt,ap);
va_end(ap);
printf("<< %s",sbuf);
write(conn,sbuf,strlen(sbuff));
}
// in main function
int main(){
const char * chanm = "test";
// Here is where I get my error, line 38
join("JOIN %s\r\n", chanm);
}
Can someone please tell me what am I doing wrong?
I get the error message:
ircbot.c:38 warning: deprecated conversion from string constant to char*
Change your function heading to:
The problem is that
"JOIN %s\r\n"is a constant string, and you were trying to pass it to a non-constantchar *. Since you don’t intend to modifyfmtwithin yourjoinfunction, you should declare it asconst char *fmt.