msg = "This is a UDP test string! (packet %d)\n", ++pktcnt
That is not how you put a formatted string into a variable in C.
You need to use sprintf
, and you need to make sure that adequate space is allocated in the string. For example
char msg[200];
sprintf(msg, "This is a UDP test string! (packet %d)\n", ++pktcnt);
Or you can put it directly into buf
:
sprintf(buf, "This is a UDP test string! (packet %d)\n", ++pktcnt);
assuming you had enough space there. Remember in C you must allocate space yourself - functions will not do it for you and you will get lots of segmentation faults until you get the message….