How to tell ping to exit after a specified number of ECHO_REQUEST packets

C++
ping -c 3 howtoforge.com
Source

Also in C++: