/* Kód */
#include <stdio.h>
#include <string.h>
char send_msg(char *msg,char *channel)
{
char privmsg[] = "PRIVMSG ";
strcat(privmsg,channel);
strcat(privmsg, " :");
strcat(privmsg,msg);
printf("%s\n",privmsg);
return *privmsg;
}
int main()
{
send_msg("Ahoj","Blabla");
}
/* Kompilovanie */
gcc strcat.c -o strcat -g
Error nebol žiadny ani warning.
/* Spustenie */
./strcat
PRIVMSG Blabla :Ahoj
Chyba segmentácie
/* gdb strcat */
Starting program: /home/st1gd3r/Desktop/C/strcat
PRIVMSG Blabla :Ahoj
Program received signal SIGSEGV, Segmentation fault.
0x413a2061 in ?? ()
Pri tom istom kóde keď zmením
return *privmsg;
na
return privmsg;
Tak:
gcc strcat.c -o strcat -g
strcat.c: In function ‘send_msg’:
strcat.c:14: warning: return makes integer from pointer without a cast
strcat.c:14: warning: function returns address of local variable
A gdb:
Starting program: /home/st1gd3r/Desktop/C/strcat
PRIVMSG Blabla :Ahoj
Program received signal SIGSEGV, Segmentation fault.
0x413a2061 in ?? ()
Všetky rady ako to opraviť vítané. Predom dík.
st1gd3r
Rady:
char privmsg[]=(char*)malloc(strlen(msg)+strlen(channel)+nejaka konstanta);