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.8 (297)
Validate Longitudinal Redundancy Checksum (LRC)Darko Kolaković C or C++ANSI5.4 (216)
Three ways to do a swapDavid Nielsen C or C++ANSI5.6 (415)
Rectangle Collision DetectionDavid Nielsen C or C++ANSI5.7 (249)
using struct tm, time_t, and time to create a simple clockDieter Manstein CANSI5.3 (50)
Find the number of CPU Cores, for Windows, Mac or LinuxDirk-Jan Kroon C or C++Multiple6.5 (150)
String FunctionsDominic Vonk 7.4 (585)
Convert an integer into binary representationElabed Soufiane CANSI5.0 (91)
euler approximation methoderic mbakop C or C++ANSI5.6 (329)
string to bitstring, bitstring to stringEsa Karjalainen CANSI5.4 (87)
View the contents of a directoryfinnepower C++Windows5.5 (244)
dynamically create and initialise 4d arrayG.Watt.Porteous CANSI5.3 (138)
Find the minimum distance between two linesGiacomo C or C++ANSI4.3 (78)
Singly linked list - insert, remove, add, countGirish Amara CANSI7.3 (2546)
Convert NTSTATUS code to Win32 errorIan Abbott C or C++Windows5.4 (147)
Simple Windows Socket Server ExampleJahan Addison C++Windows5.5 (197)
Dynamically Allocating a Multidimensional ArrayJared Hendrickson CANSI4.5 (77)
Palindrome FunctionJason Weeks 7.4 (564)
An example use of a function pointerJayesh C++ANSI5.7 (107)
A very simple frames per second functionJeff Verkoeyen C or C++Windows5.8 (309)
Quick-sort using vector and iterator in STLJianbao Tao 7.3 (555)
Calandar generator printing a full calendar for any yearJoe C++ANSI6.6 (437)
Implementing a directory listing on LinuxJoshith C*nix5.1 (89)
GetLastError error lookup toolKen Fitlike CWindows5.4 (245)
Another way to swap 2 numbersMaganti Venkatesh C or C++ANSI5.4 (100)
a short BubbleSort algoritm for Integer ArraysMajor_Small C or C++ANSI6.2 (328)
A function to encrypt/decrypt a string using XOR eMajor_Small C++ANSI6.2 (620)
A function to reverse an integer arrayMajor_Small C or C++ANSI5.9 (599)
Another merge sort of integer listManoj CANSI5.6 (90)
Output console text with type-writer effect.Michael Brandon Miller 7.3 (545)
Next 30
Previous 30