C and C++ Source Code Snippets

Welcome to Cprogramming.com's programming code snippet repository. Peruse the archives or add your own snippets for others to use! (Check the following link a better definition of a snippet)

Sort by clicking on any of the headers.

SnippetAuthorLanguagePlatformRating (votes)
Three ways to do a swapDavid Nielsen C or C++ANSI6.3 (317)
Rectangle Collision DetectionDavid Nielsen C or C++ANSI6.2 (168)
using struct tm, time_t, and time to create a simple clockDieter Manstein CANSI5.7 (8)
Find the number of CPU Cores, for Windows, Mac or LinuxDirk-Jan Kroon C or C++Multiple7.2 (13)
Convert an integer into binary representationElabed Soufiane CANSI6.2 (14)
euler approximation methoderic mbakop C or C++ANSI5.9 (255)
string to bitstring, bitstring to stringEsa Karjalainen CANSI7.1 (16)
View the contents of a directoryfinnepower C++Windows6.9 (159)
dynamically create and initialise 4d arrayG.Watt.Porteous CANSI9.0 (28)
Find the minimum distance between two linesGiacomo C or C++ANSI6.6 (9)
Singly linked list - insert, remove, add, countGirish Amara CANSI7.4 (202)
Convert NTSTATUS code to Win32 errorIan Abbott C or C++Windows8.8 (32)
Simple Windows Socket Server ExampleJahan Addison C++Windows6.5 (29)
Dynamically Allocating a Multidimensional ArrayJared Hendrickson CANSI5.8 (9)
An example use of a function pointerJayesh C++ANSI6.8 (12)
A very simple frames per second functionJeff Verkoeyen C or C++Windows5.7 (190)
Calandar generator printing a full calendar for any yearJoe C++ANSI6.7 (20)
Implementing a directory listing on LinuxJoshith C*nix5.7 (9)
GetLastError error lookup toolKen Fitlike CWindows5.8 (182)
Another way to swap 2 numbersMaganti Venkatesh C or C++ANSI7.2 (22)
a short BubbleSort algoritm for Integer ArraysMajor_Small C or C++ANSI6.0 (199)
A function to reverse an integer arrayMajor_Small C or C++ANSI6.6 (356)
A function to encrypt/decrypt a string using XOR eMajor_Small C++ANSI6.7 (340)
Another merge sort of integer listManoj CANSI5.9 (10)
similar to gotoxy; minimal screen control for wyseMike Kinney C or C++ANSI5.8 (156)
Print variables with file and line number for debuggingmike lear C++ANSI6.2 (10)
Count number of bits in a numberNaren Bala C or C++ANSI5.1 (9)
Shorter version of gotoxyNedeljko CLinux7.8 (25)
A game setup for DirectXPaul D C or C++ANSI6.3 (229)
Calculates 1 variable statisticsPaul Kennedy C++ANSI5.3 (8)
Next 30
Previous 30

Add a snippet!