I’m trying to learn more about C and I was wondering if anyone could clarify what’s going on here. I’m getting a compiler warning: “warning: assignment makes integer from pointer without a cast @ msg[msglen+1] = “\0″”
char *msg = NULL;
int len = 10;
int msglen = 0;
while(<argument>) {
msg = (char *)calloc(len, 1);
strncpy(msg, <some string>, len);
msglen = strlen(msg);
msg[msglen+1] = "\0";
Thanks, I appreciate you help!
a “\0” is treated as a constant string, and the address to that string is slapped into place when you try to do
msg[len - 1] = "\0"hence you get the message “converts…”do this instead
msg[len - 1] = '\0'