I am working on a network related project wherein I need to transfer a structure data containing float
variables. I know I can convert int
and short
variables to network byte order using htons
and htonl
functions, but are there any inbuilt functions for converting float
and double
variables to network byte order? Can somebody help me how to do this.
struct Employee
{
float EmployeeSalary;
unsigned short EmployeeId;
...
};
int main()
{
struct Employee emp;
emp.EmployeeSalary=1234.567;
emp.EmployeeId=123;
struct Employee TempEmp;
TempEmp.EmployeeSalary=?;
TempEmp.EmployeeId=htons(emp.EmployeeId);
char buf[100];
memcpy(buf,Tempemp,sizeof(Employee));
//send the buf data via sendto function
}
Also can somebody explain me how to do the same conversions for structs containing bit field data.