The example now works with my server and database.
Thanks to Scorpions4ever for the nice example and thanks to b49P23TIvg for help with the link order.
I might add that DBSERVER in the example should refer to the server section in freetds.conf. I could not make it work with either an IP address or an IP address and port number.
In the .c file:
#define DBSERVER "sqlserver"
In the freetds.conf file:
host = <IP address of your server>
port = <Port number, usually 1433 for MSSQL servers>
tds version = <TDS version for your server, I use "8.0" for my SQL Server 2012 Express>