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)
Converts a real number to the string.Darko Kolakoviћ C or C++ANSI5.7 (251)
Validate Longitudinal Redundancy Checksum (LRC)Darko Kolaković C or C++ANSI5.3 (168)
Three ways to do a swapDavid Nielsen C or C++ANSI5.6 (374)
Rectangle Collision DetectionDavid Nielsen C or C++ANSI5.5 (202)
using struct tm, time_t, and time to create a simple clockDieter Manstein CANSI5.2 (13)
Find the number of CPU Cores, for Windows, Mac or LinuxDirk-Jan Kroon C or C++Multiple5.1 (62)
String FunctionsDominic Vonk 7.4 (499)
Convert an integer into binary representationElabed Soufiane CANSI3.4 (45)
euler approximation methoderic mbakop C or C++ANSI5.4 (281)
string to bitstring, bitstring to stringEsa Karjalainen CANSI4.8 (54)
View the contents of a directoryfinnepower C++Windows5.5 (209)
dynamically create and initialise 4d arrayG.Watt.Porteous CANSI4.9 (98)
Find the minimum distance between two linesGiacomo C or C++ANSI2.9 (36)
Singly linked list - insert, remove, add, countGirish Amara CANSI7.2 (2129)
Convert NTSTATUS code to Win32 errorIan Abbott C or C++Windows4.9 (97)
Simple Windows Socket Server ExampleJahan Addison C++Windows5.4 (148)
Dynamically Allocating a Multidimensional ArrayJared Hendrickson CANSI2.4 (36)
Palindrome FunctionJason Weeks 7.4 (501)
An example use of a function pointerJayesh C++ANSI3.6 (43)
A very simple frames per second functionJeff Verkoeyen C or C++Windows5.3 (232)
Quick-sort using vector and iterator in STLJianbao Tao 7.4 (497)
Calandar generator printing a full calendar for any yearJoe C++ANSI6.3 (303)
Implementing a directory listing on LinuxJoshith C*nix4.1 (47)
GetLastError error lookup toolKen Fitlike CWindows5.2 (210)
Another way to swap 2 numbersMaganti Venkatesh C or C++ANSI4.4 (53)
a short BubbleSort algoritm for Integer ArraysMajor_Small C or C++ANSI5.5 (230)
A function to encrypt/decrypt a string using XOR eMajor_Small C++ANSI5.5 (455)
A function to reverse an integer arrayMajor_Small C or C++ANSI5.5 (481)
Another merge sort of integer listManoj CANSI4.1 (47)
Output console text with type-writer effect.Michael Brandon Miller 7.4 (501)
Next 30
Previous 30

Add a snippet!