More than likely a rookie question, but I'm looking for a printf
-esque function for use in send
over TCP sockets. This is for a simple chat server, specifically a modified version of the one in Beej's socket guide. I'm prepared to write my own, but before I do I want to make sure I'm not reinventing the wheel.
I'm looking for something native to C, not a library or something. I'm doing this as an intellectual pursuit, and using a ready-made library isn't going to teach me as well as messing up until I get it right and understand why.
Appreciation in advance for anyone who answers!
Edit: I'm currently using:
if(current_user->fs_id == sending_user->fs_id) {
snprintf(server->current_buffer, buffer_size, "You said: %s", message);
} else {
snprintf(server->current_buffer, buffer_size, "%s said: %s", sending_user->name, message);
}
if(send(current_user->fs_id, server->current_buffer, buffer_size, 0) == -1) {
perror("Sending data");
}
I understand this isn't the best way to do it, that's part of what I'm fixing now.