I have been trying to check Internet connection but all ways I have tried have failed. Some example code would be great, or the package to use. Thanks very much.

What compiler and OS?

Linux, and it is using gcc to compile it.

I got it working. I used if(system(ping -c 1 www.google.com)){ printf("Not Connected"); }

FYI: I couldn't edit the old post, it was past 30 minutes.

The easiest way is to use a socket to connect to a known stable server. If it succeeds you now know you've got an internet connection. If it fails, you can use error messages or assumptions to determine the status.