I am trying to concatenate two values that are returned from two different functions, a Server IP Address and a Student ID. The functions used to get these have been void function in order to access the server. I am wanting to use strcat()
function but I can't get it to work successfully. The following code successfully returns both of the single values from the server.
void get_ipaddress(void)
{
int fd;
struct ifreq ifr;
printf("IP Address:");
fd = socket(AF_INET, SOCK_DGRAM, 0);
/* I want to get an IPv4 IP address */
ifr.ifr_addr.sa_family = AF_INET;
/* I want an IP address attached to "eth0" */
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ-1);
ioctl(fd, SIOCGIFADDR, &ifr);
close(fd);
/* Display result */
printf("%s\n", inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr));
}
void get_studentid(int socket)
{
char studentid[32];
size_t k;
readn(socket, (unsigned char *) &k, sizeof(size_t));
readn(socket, (unsigned char *) studentid, k);
printf("Student ID: %s\n", studentid);
} // end get_studentid()
I am trying to get the output
192.168.229.128: S1427722
Any code that I have previously tried returned the error
invalid use of void expression